Dim dt As Table = Tables("表A")
If dt.Rows.Count > 0 Then
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Add
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
App.DisplayAlerts = False
ws.name ="库存表"
For c As Integer = 0 To dt.Cols.Count -1 '添加列标题
ws.Cells(1, c+1).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
If dt.cols(c).IsDate Then
ws.cells(r+2, c+1).NumberFormat = "yyyy-m-d h:mm:ss"
End If
ws.cells(r+2, c+1).Value = dt.rows(r)(c)
Next
Next
Dim Rg As MSExcel.Range = Ws.Cells
Rg.EntireColumn.AutoFit '自动调整列宽
'Rg.WrapText = True
'Rg.EntireRow.AutoFit '自动调整行高
wb.Saveas("d:\导出数据.xls")
'app.visible = True
End If