始终都要打开一个Excel进程,这是没有办法的
Dim dt As Table = CurrentTable '当前表
Dim App As New MSExcel.Application
Dim Wb As MSExcel.Workbook = App.WorkBooks.Open(ProjectPath & "\数据源.xlsm")
Dim Ws As MSExcel.WorkSheet = Wb.worksheets("数据表")
Dim Rg As MSExcel.Range = Ws.UsedRange
Rg.Delete
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
ws.cells(r+2, c+1).Value = dt.rows(r)(c)
Next
Next
app.visible = False
Wb.Save
App.Quit