Foxtable(狐表)用户栏目专家坐堂 → [求助]导入EXCEL时格式转换(已解决)


  共有2092人关注过本帖树形打印复制链接

主题:[求助]导入EXCEL时格式转换(已解决)

帅哥哟,离线,有人找我吗?
gfj7126
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:130 积分:1141 威望:0 精华:0 注册:2013/6/9 11:20:00
[求助]导入EXCEL时格式转换(已解决)  发帖心情 Post By:2016/7/15 10:02:00 [只看该作者]

求教:以下是我要导入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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
gfj7126
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:130 积分:1141 威望:0 精华:0 注册:2013/6/9 11:20:00
  发帖心情 Post By:2016/7/15 11:37:00 [只看该作者]

已解决

select case m

  case ?1

   dr(nms(m)) = Cint(sheet(n,m).value)

  case else

  dr (nms(m)) = sheet(n,m).value

  end select

 


 回到顶部