I want to create one excel sheet where, I want to create tab with all date of particular month's. like tab name- 1 jan, 2jan, 3jan.....etc. also I have date-wise datatable like datatable1jan,datatble2jan,datatable3jan....etc. I want to create excel with this datatable and tab name.
I know how to create excel using Interlop which as folllows,
Public static void CreateExcel_TabNameUnique( DataTable dt1,string ExcelFilePath, string Tab_Name1)
{
try
{
runDate = DateTime.Today;
currMonth = DateTime.Today;
object missing = Type.Missing;
Excel.Application oXL = new Excel.Application();
oXL.Visible = false;
Excel.Workbook oWB = oXL.Workbooks.Add(missing);
Excel.Worksheet oSheet = oWB.ActiveSheet as Excel.Worksheet;
oSheet.Name = Tab_Name1;
for (int i = 0; i < dt1.Columns.Count; i++)
{
oSheet.Cells[1, (i + 1)] = dt1.Columns[i].ColumnName;
}
for (int i = 0; i < dt1.Rows.Count; i++)
{
for (int j = 0; j < dt1.Columns.Count; j++)
{
oSheet.Cells[(i + 2), (j + 1)] = dt1.Rows[i][j];
}
}
if (ExcelFilePath != null && ExcelFilePath != "")
{
try
{
oWB.SaveAs(ExcelFilePath, Excel.XlFileFormat.xlOpenXMLWorkbook,
missing, missing, missing, missing,
Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing, missing, missing);
oWB.Close(missing, missing, missing);
oXL.UserControl = true;
oXL.Quit();
}
catch (Exception ex)
{
throw new Exception("ExportToExcel: Excel file could not be saved! Check filepath.\n"
+ ex.Message);
}
}
}
catch (Exception ex)
{
}
}
Please help me.