以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助] (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=113482) |
-- 作者:zxmonkey -- 发布时间:2018/1/16 18:37:00 -- [求助] 求职各位大神, 现有需要给已有的数据表中导入某一列数值,使用下面的代码,excel中的价格和数量单位这两列的数值不能导入表中,哪位大神看看有什么问题!谢啦 Tables("表A").AllowEdit=True
Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "EXCEL文件|*.XLS" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim c As Integer = 0 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("表A").StopRedraw() \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致 Dim nms() As String = {"客户编码","货号","尺寸_宽度","货描","材料","数量单位","价格"} \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 1 To Sheet.Rows.Count - 1 Dim bh As String = sheet(n,1).Text If DataTables("表A").SQLFind("货号 = \'" & bh & "\'") IsNot Nothing Then \'如果存在同编号的货号 c=c + 1 Dim dr As DataRow = DataTables("表A").SQLFind("货号 = \'" & bh & "\'") Dim m As Integer = nms.Length - 2 Dim y As Integer = nms.Length - 1 dr("价格") = Sheet(n,y).Value dr("数量单位") = Sheet(n,m).value End If Next Tables("表A").ResumeRedraw() MessageBox.Show("导入完成,共导入" & c & "条记录") Tables("表A").save End If |
-- 作者:有点蓝 -- 发布时间:2018/1/16 20:17:00 -- 表A的数据很多吗,万几千行的全部加载再查询,就不用每行保存一次了, Tables("表A").AllowEdit=True Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "EXCEL文件|*.XLS" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim c As Integer = 0 Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("表A").StopRedraw() \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致 Dim nms() As String = {"客户编码","货号","尺寸_宽度","货描","材料","数量单位","价格"} \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 1 To Sheet.Rows.Count - 1 Dim bh As String = sheet(n,1).Text Dim dr As DataRow = DataTables("表A").SQLFind("货号 = \'" & bh & "\'") If dr IsNot Nothing Then \'如果存在同编号的货号 c=c + 1 Dim m As Integer = nms.Length - 2 Dim y As Integer = nms.Length - 1 dr("价格") = Sheet(n,y).Value dr("数量单位") = Sheet(n,m).value dr.Save End If Next Tables("表A").ResumeRedraw() MessageBox.Show("导入完成,共导入" & c & "条记录") Tables("表A").save End If |