System.Data.DataTable dtMainSQLData = new System.Data.DataTable(); da.Fill(dtMainSQLData); DataColumnCollection dcCollection = dtMainSQLData.Columns; // Export Data into EXCEL Sheet Microsoft.Office.Interop.Excel._Application ExcelApp = new Excel.Application(); ExcelApp.Application.Workbooks.Add(Type.Missing); // ExcelApp.Cells.CopyFromRecordset(objRS); for (int i = 1; i < dtMainSQLData.Rows.Count + 1; i++) { for (int j = 1; j < dtMainSQLData.Columns.Count + 1; j++) { if (i == 1) ExcelApp.Cells[i, j] = dcCollection[j - 1].ToString(); else ExcelApp.Cells[i, j] = dtMainSQLData.Rows[i - 1][j - 1].ToString(); } } ExcelApp.ActiveWorkbook.SaveCopyAs("E:\\1.xls"); ExcelApp.ActiveWorkbook.Saved = true; ExcelApp.Quit(); MessageBox.Show("Data Exported Successfully");
header L U R Sr.no A B C 1 1 1 1 Particular A A 11 1 0 0 2 Particular A B 12 5 0 0 Particular A 7 1 1 3 Particular B A 13 5 1 0 4 Particular B B 14 0 0 3 Particular B 5 1 3
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)