我导出的数据表标题是两行,以下代码不知道早哪出问题,标题是有正常生成,但数据始终少了一行。
Dim dt As Table = Tables("订单列表")
Dim nms() As String = {"订单编号","快递公司","快递单号"} '要导出的列名
Dim caps() As String = {"订单编号","快递公司(必填)","快递单号"} '对应的列标题
Dim capt() As String = {"order_sn","shipping_name","shipping_sn"} '对应的列标题
Dim szs() As Integer = {200,300,300} '对应的列宽
Dim Book As New XLS.Book '定义一个Excel工作簿
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
For c As Integer = 0 To nms.length -1
Sheet(0, c).Value = caps(c) '指定列标题
Sheet(1, c).Value = capt(c) '指定列标题
Sheet.Cols(c).Width = szs(c) '指定列宽
Next
For r As Integer = 1 To dt.Rows.Count - 1 '填入数据
For c As Integer = 0 To nms.length -1
Sheet(r +1, c).Value = dt.rows(r)(nms(c))
Next
Next
Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then
Book.Save(dlg.FileName)
Dim Proc As New Process
Proc.File = dlg.FileName
Proc.Start()
End If