2009年4月16日 星期四

將DataTable 寫入至 Excel

寫程式對Excel的存取是一件常見的事~~~
以下程式示範如何將DataTable 寫入至 Excel


Dim xlApp As New Excel.Application
Dim xlBooks As Excel.Workbooks = xlApp.Workbooks
Dim xlBook As Excel.Workbook = xlBooks.Open("\\db-machine\db-file\test.xls")
Dim xlSheet As Excel.Worksheet = xlApp.ActiveSheet


For i As Integer = 0 To dt.Rows.Count - 1
For j As Integer = 0 To dt.Columns.Count - 1
book.Sheets(1).Cells(i+1, j+1) = dt.Rows(i)(j)
Next
Next

沒有留言:

##EasyReadMore##