以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- Excel工作表合并 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=148433) |
||||
-- 作者:rgbjwjb -- 发布时间:2020/4/7 22:44:00 -- Excel工作表合并 我想把工作簿中的所有数据表合并到“收款”一个表中,代码为: Dim dlg As New OpenFileDialog \'定义一个新的OpenFileDialog dlg.Filter= "Excel文件|*.xls;*.xlsx" \'设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮 Dim Book As New XLS.Book(dlg.FileName) Tables("收款").StopRedraw() For i As Integer = 0 To Book.Sheets.Count -1 Dim Sheet As XLS.Sheet = Book.Sheets(i) Dim nms() As String = {"债权人","借款日期","借款期限","利率","收取金额","票号","凭证号","备注"} For n As Integer = 1 To Sheet.Rows.Count -1 Dim r As Row = Tables("收款").AddNew() For m As Integer = 0 To nms.Length - 1 r(nms(m)) = Sheet(n,m).Value Next Next Next Tables("收款").ResumeRedraw() End If DataTables("收款").Deletefor("票号 is null") 最后只导成功一条,请问代码要如何修改?谢谢,请指教!
|
||||
-- 作者:有点蓝 -- 发布时间:2020/4/7 23:11:00 -- 我测试没有问题,不过可以改进一下 …… Dim nms() As String = {"债权人","借款日期","借款期限","利率","收取金额","票号","凭证号","备注"} For n As Integer = 1 To Sheet.Rows.Count -1 If Sheet(n,0).Value.trim() > "" Then Dim r As Row = Tables("收款").AddNew() For m As Integer = 0 To nms.Length - 1 r(nms(m)) = Sheet(n,m).Value Next end if Next ……
|