比较麻烦,这样就必须换一种方式导出了,参考(二维数组导出)
on error resume Next
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim dt As Table = Tables("订单")
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook
If FileSys.FileExists(dlg.FileName) Then
wb = App.WorkBooks.Open(dlg.FileName)
Else
wb = App.WorkBooks.Add
End If
Dim arr(0 To dt.Rows.count,0 To dt.Cols.count-1) As Object '定义二维数组
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets("订单")
If ws Is Nothing Then
ws = Wb.WorkSheets.add
ws.name = "订单"
Else
Ws.UsedRange.clear
End If
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
arr(0,c) = 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
arr(r+1, c) = dt.rows(r)(c)
Next
Next
Dim Rg2 As MSExcel.Range = Ws.Range("A1:" & ws.cells(dt.Rows.count+1, dt.Cols.count).address) '定义Excel中写入的区域
Rg2.Value = arr
app.visible = True
End If