求教:以下是我要导入EXCEL中的数据的代码。但其中在导入销售数量,箱数,单价列时,发现EXCEL中的这三列的内容是文本格式,当然去改EXCEL表是可以的,但EXCEL表数据太大时,工作量太大,同时也可能会改错,所以,在我下面的代码中如何判断在导入这三列时,转换数字格式导入?
Dim dlg As new OpenFileDialog
dlg.Filter = "excel文件|*.xls;*.xlsx"
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.OK Then
For Each f As String In dlg.FileNames
Dim Book As New XLS.Book(f)
Dim Sheet As xls.Sheet = Book.Sheets(0)
Tables("销售实绩表").StopRedraw()
Dim nms() As String = {"","","","","","","产品型号","","","产品批号","","","","","","有效期限","","","注册证号","","","","单位","销售数量","箱数","","单价"}
For n As Integer = 35 To Sheet.Rows.Count -1
Dim ddh As String = sheet(6,8).text
Dim rq As Date = sheet(13,8).text
Dim kh As String = sheet(21,12).text
Dim ph As String = sheet(n,9).text
Dim dz As String = sheet(25,13).text
MessageBox.Show("'"& ph &"'")
If ph = "" Then
DataTables("销售实绩表").LoadFilter = "[_Locked] = false"
DataTables("销售实绩表").Load
Tables("销售实绩表").ResumeRedraw()
Exit For
Else
Dim dr As DataRow = DataTables("销售实绩表").sqlFind("订单号 = '" & ddh & "' and 产品批号 = '"& ph &"'")
If dr Is Nothing Then '如果不存在同编号的订单
dr = DataTables("销售实绩表").AddNew()
dr("订单号") = ddh
dr("订单日期") = rq
dr("客户") = kh
dr("发货地址") = dz
End If
For m As Integer = 6 To nms.Length - 1
If nms(m) > "" Then
dr(nms(m)) = Sheet(n,m).Value
End If
Next
End If
Next
Tables("销售实绩表").ResumeRedraw()
Next
End If
[此贴子已经被作者于2016/7/15 11:39:19编辑过]