Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件(*.xlsx;*.xls)|*.xlsx;*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Dim Book As New XLS.Book '定义一个Excel工作簿
Book.Sheets.RemoveAt(0)
For Each dt As Table In Tables
Dim Sheet As XLS.Sheet = Book.Sheets.Add(dt.Name) '引用工作簿的第一个工作表
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
Sheet(0, c).Value = dt.Cols(c).Name
Next
For r As Integer = 0 To dt.Rows.Count - 1 '填入数据
For c As Integer = 0 To dt.Cols.Count -1
Sheet(r +1, c).Value = dt.rows(r)(c)
Next
Next
Next
MessageBox.Show("导出完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Book.Save(dlg.FileName)
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If