目前以下代码已解决“”sheet1“”的导入,如何将Excel中所有sheet都导入进去?
导入代码
For Each fl As String In dlg.FileNames
Dim mg As New Merger
mg.SourcePath = fl
if fl.EndsWith(".xls")
mg.Format = "excel" '指定格式
else
mg.Format = "excel2007" '指定格式
end if
mg.SourceTableName = "sheet1$" '指定要合并的表
mg.DataTableName = "sheet1" '指定接收数据的表
mg.Merge() '开始合并
Next
历遍代码
Dim Book As New XLS.Book(fl)
for each Sheet As XLS.Sheet in Book.Sheets
Dim mg As New Merger
mg.SourcePath = fl
mg.Format = "excel2007" '指定格式
mg.SourceTableName = Sheet.name & "$" '指定要合并的表
mg.DataTableName = "sheet1" '指定接收数据的表
mg.Merge() '开始合并
Next
For Each fl As String In dlg.FileNames
Dim Book As New XLS.Book(fl)
For Each Sheet As XLS.Sheet In Book.Sheets
Dim mg As New Merger
mg.SourcePath = fl
If fl.EndsWith(".xls") Then
mg.Format = "excel" '指定格式
Else
mg.Format = "excel2007" '指定格式
End If
mg.SourceTableName = Sheet.name & "$" '指定要合并的表
mg.DataTableName = "sheet1" '指定接收数据的表
mg.Merge() '开始合并
Next
Next