Dim dt As Table = Tables("中考报名_table3")
Dim dt1 As Table = Tables("中考报名_table4")
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excl|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
Dim sheet1 As XLS.Sheet = Book.Sheets(1)
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
If dt.Cols(c).Visible Then
Sheet(0, c).Value = dt.Cols(c).Name
End If
Next
For m As Integer = 1 To dt.Rows.Count -1
For n As Integer = 0 To dt.Cols.count -1
If dt.Cols(n).Visible Then
sheet(m,n).value =dt.Rows(m)(dt.Cols(n).name)
End If
Next
Next
For c1 As Integer = 0 To dt1.Cols.Count -1 '添加列标题
If dt1.Cols(c1).Visible Then
Sheet1(0, c1).Value = dt1.Cols(c1).Name
End If
Next
For m1 As Integer = 1 To dt1.Rows.Count -1
For n1 As Integer = 0 To dt1.Cols.count -1
If dt1.Cols(n1).Visible Then
sheet1(m1,n1).value =dt1.Rows(m1)(dt1.Cols(n1).name)
End If
Next
Next
Book.Save(dlg.FileName )
Dim Proc As New Process
Proc.File = dlg.filename
Proc.Start()
End If
老师,请问上面代码想同时将窗口内两个表导出到EXCLsheet(0),sheet(1),提示下面错误
索引超出范围。必须为非负值并小于集合大小。没看懂什么地方错了,请指教,谢谢