----------Vb.net exported data to Excel -------------
Introducing Microsoft Excel 11.0 Object Library Dim oExcel As New Excel.Application Dim obook As Excel.Workbook Dim in which reference 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 ing = 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 data to Excel rows (columns), array of source data to correspond to Excel's row (column).
The above code is used is a DataGrid control, if it is the same as Table?
Array size can be defined by themselves. If the number of data is larger than the range of array, then the array is accurate (who is called to use array output :-)) BTW: The machine is equipped with office to reference the Microsoft Excel 11.0 Object Library path is * / Microsoft Office / Office11 / Execl.exe first write blog, what is wrong, please give pointed out ------------------------------------------------------------------------------------------------ -----------------------