以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]导入excle表到项目 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=176182) |
-- 作者:miaoqingqing -- 发布时间:2022/4/2 20:39:00 -- [求助]导入excle表到项目 求助,狐表中表A第一列,导入外部Excel表A的第一列, 如果狐表中表A第一列,已含有Excel表A的第一列的值,就跳过不导入,下面代码怎么修改? 下面代码是把Excel表全部行都进来了 Dim dlg As New OpenFileDialog dlg.Filter = "Excel文件|*.xls;*.xlsx" If dlg.ShowDialog = DialogResult.OK Then Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Tables("表A").StopRedraw() \'注意以下数组中列名称的顺序,必须和Excel表中的列顺序一致 Dim nms() As String = {"第一列","试题号","题型","题目",“”,“”,“”,"分类","选择题_A","选择题_B","选择题_C","选择题_D","判断题_A","判断题_B","正确表A"} \'注意下面的循环变量从1开始,而不是从0开始,因为Excel表的第一行是标题 For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As Row = Tables("表A").AddNew() For m As Integer = 0 To nms.Length - 1 if nms(m) > "" then r(nms(m)) = Sheet(n,m).Value end if Next Next Tables("表A").ResumeRedraw() End If [此贴子已经被作者于2022/4/3 17:51:34编辑过]
|
-- 作者:有点蓝 -- 发布时间:2022/4/5 20:17:00 -- For n As Integer = 1 To Sheet.Rows.Count -1 dim r as datarow = dataTables("表A").find("第一列=\'" & Sheet(n,0).Value & "\'") if r is nothing then r = Tables("表A").AddNew() For m As Integer = 0 To nms.Length - 1 if nms(m) > "" then r(nms(m)) = Sheet(n,m).Value end if Next end if Next |