vb.net - Multiple datagrids to one excel sheet -


I have the following code that will move the records from my datagrid to my Excel spreadsheet. At present, this code works for a datagrid excel sheet. Now I need to improve the code below so that it can work for many datagrids. I want to help to expand this code so that I can drag down the records from 3 data grids under one another under the same Excel sheet.

Microsoft.Office.Interop.Excel.Application excel = Dynamic Excel. Try new Microsoft.Office.Interop.Excel.Application excel.Workbooks.Open ("C: \ satish \ TestExcel \ vbexcel .xlsx ") I leave the block from the DGV elese if you want the column header as the integer as the integer, the dull diff as the integer = 1 '' '' '' DataGrid View 1 for j = 0 for "" "" "" "" "" "" "" "" "" "" "" "" ".ColumnCount - 1 excel.Worksheets (1) .cells (1, j + 1) = DataGridView1.Columns (j) .Name Next diff + = 1 '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' I = 0 to DataGridView4.RowCount - 1, then DataGridView4.Rows (i) .IsNewRow = False then JK for "" "" "" "" "" "" "" For = 0 DataGridView4.ColumnCount - 1 excel.Worksheets (1) .cells (i + diff, j + 1) = DataGridView4.Item (j, i) .Value next end then next excel.Worksheets (1). Select () excel.ActiveWorkbook () Save () excel.Workbooks.Close () excel.Quit () excel does not catch anything in the form of the system. time to time. Enterprises COMException Message Box Show Error ("Error accessing XC:" + ex.ToString ()) Try the end of messageBox.Show ("Error:" + ex.ToString ()) as the pre-exception capture

postprop = "text">

  Integer = 1 as intExcelRow As for the integer I = 1 3 dim your DataAdGridView in the form of DataGridView = Me.Controls ("YourDataGridView" & amp; i) 'First DataGridView's Title Only' Removal I = 1 You Print 3 Different Headers For the sake of I want to = 1 then for intColumn = 0 to yourDataGridView.ColumnCount - 1 excel.Worksheets (1) .cells (intExcelRow, intColumn + 1) = YourDataGridView.Columns (intColumn) .Name Next intColumn intExcelRow = intExcelRow +1 end then intRow = 0 to yourDataGridView.RowCount - 1, then yourDataGridView.Rows (intRow) .IsNewRow = False then intColumn = 0 to yourDataGridView. ColumnCount - 1 excel.Worksheets (1) .cells (intExcelRow, intColumn + 1) = YourDataGridView.Item (intColumn, intRow) .Value Next intColumn intExcelRow = intExcelRow + 1 End I  
Then next intRow Next

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -