----------vb.net export data to Excel-------------
Introduce Microsoft Excel 11.0 Object Library in references
Dim oExcel As New Excel.Application
Dim obook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim DataArray(2000, 2000) As Integer
obook = oExcel.Workbooks.Open("c:\1.xls")
oSheet = obook.Worksheets(1)
oSheet.Name = "ok"
Dim myAdapter As New OleDb.OleDbDataAdapter("select * from list", Module1.dbConn)
Dim mydataset As New DataSet
myAdapter.Fill(mydataset, "list")
DataGrid1.DataSource = mydataset.Tables("list")
Dim i As Integer
Dim iCount As Integer
iCount = mydataset.Tables("list").Rows.Count
For i = 0 To iCount - 1
DataArray(i, 0) = DataGrid1.Item(i, 0)
Next
oSheet.Range("b1").Resize(100, 1).Value = DataArray
obook.Save()
oExcel.Quit()
Add the rows (columns) of data to Excel, and the array of source data corresponds to the rows (columns) of Excel.
The code above uses the DataGrid control, which is the same if you use a table.
The size of the array can be defined by itself, and if the number of data is greater than the range of the array, then the array is the name (who wants to output it with an array):-)
BTW: The machine will be able to refer to the Microsoft Excel 11.0 Object Library when it has Office installed
Path is *\microsoft Office\office11\execl.exe
The first time to write a blog, what is wrong to write, master please advise
--------------Finish-------------------------------