MyExcel.Application excelApp = new MyExcel.Application(); excelApp.Workbooks.Add(); MyExcel._Worksheet workSheet = excelApp.ActiveSheet; for (int i = 0; i < Tbl.Columns.Count; i++) { workSheet.Cells[1, (i + 1)] = Tbl.Columns[i].ColumnName; } for (int i = 0; i < Tbl.Rows.Count; i++) { for (int j = 0; j < Tbl.Columns.Count; j++) { workSheet.Cells[(i + 2), (j + 1)] = Tbl.Rows[i][j]; } } if (ExcelFilePath != null && ExcelFilePath != "") { try { workSheet.SaveAs(ExcelFilePath); excelApp.Quit(); MessageBox.Show("Data is exported to Excel successfully!", "Successfull", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("ExportToExcel: Excel file could not be saved! Check filepath.\n" + ex.Message); } } else { excelApp.Visible = true; }
Range rng = Worksheets.Cells(r,c);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)