I will have to take a look at the code more intently. And as such will update this solution as needed. The first thing I can see by just scanning the code:
Have you thought of using a excel template. This way you do not need to create a new excel sheet etc from scratch but rather use a template. Beside this will be much faster even if the template is a sheet with no data etc.
2nd.
Quote:
for (int j = 1; j < table.Columns.Count + 1; j++)
{
ExcelApp.Cells[1, j] = table.Columns[j - 1].ColumnName;
}
for (int k = 0; k < table.Rows.Count; k++)
{
for (int l = 0; l < table.Columns.Count; l++)
{
ExcelApp.Cells[k + 2, l + 1] =
table.Rows[k].ItemArray[l].ToString();
}
}
ExcelApp.Columns.AutoFit();
}
easier way to do this will be to rather just add cell for cell by using a counter and increasing the row with each new line. Basically setting the dataset table = to excel 'table'/sheet
so rather use the loop you have to get the data from dt but then set it = to the cell. The nice feature of EPPlus is null will fill in a ""(Blank) value into cell
basically.
foreach(DataRow row in table)
{
int row = 1
for (int l = 0; l < table.Columns.Count; l++)
{
ExcelApp.Cells[row, l + 1] =
row.ItemArray[l].ToString();
}
row++;
}
Hope this will get you started on a solution to help make the code better/faster