Foxtable(狐表)用户栏目专家坐堂 → [求助]导入EXCEL,提示从字符串“”到类型“Double”的转换无效


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

主题:[求助]导入EXCEL,提示从字符串“”到类型“Double”的转换无效

帅哥,在线噢!
冷泉
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:392 积分:3176 威望:0 精华:0 注册:2019/4/13 16:10:00
[求助]导入EXCEL,提示从字符串“”到类型“Double”的转换无效  发帖心情 Post By:2021/12/16 16:10:00 [只看该作者]

老师,麻烦指导下,数量和采购价这2列在狐表里面是双精度,导入会提示错误代码    从字符串“”到类型“Double”的转换无效。要如何修正了,麻烦老师指导下,谢谢
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "EXCEL文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)

Tables("采购表").StopRedraw()
Dim Cols1() As String = {"编号","类别","名称","规格","单位","数量","采购价"}
Dim Cols2() As String = {"编号","类别","名称","规格","单位","数量","采购价"}
For dr1 As Integer = 1 To Sheet.Rows.Count -1
     Dim dr2 As DataRow =DataTables("采购表").AddNew()
   For i As Integer = 0 To Cols1.Length - 1
       dr2(Cols2(i)) = sheet(dr1,i).text
   Next
Next
Tables("采购表").ResumeRedraw()
End If

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


加好友 发短信
等级:管理员 帖子:47497 积分:251403 威望:0 精华:91 注册:2008/6/17 17:14:00
  发帖心情 Post By:2021/12/16 16:18:00 [只看该作者]

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "EXCEL文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables("采购表").StopRedraw()
    Dim Cols1() As String = {"编号","类别","名称","规格","单位","数量","采购价"}
    Dim Cols2() As String = {"编号","类别","名称","规格","单位","数量","采购价"}
    For dr1 As Integer = 1 To Sheet.Rows.Count -1
        Dim dr2 As DataRow =DataTables("采购表").AddNew()
        For i As Integer = 0 To Cols1.Length - 1
            Select Case Cols2(i)
                Case "数量","采购价"
                    dr2(Cols2(i)) = val(sheet(dr1,i).text)
                Case Else
                    dr2(Cols2(i)) = sheet(dr1,i).text
            End Select
        Next
    Next
    Tables("采购表").ResumeRedraw()
End If

 回到顶部