I've been trying to find a solution for this but haven't been able to find any yet. So what is happening is that when I do:
IXLWorksheet sheetSave = wb.Worksheets.Add("SheetName");
I get an Excel sheet that as 1048576 rows and 20Columns. If I send a datatable same thing happens, it places the table but the sheet still as 1048576 rows, This makes the file have a size of 5MB with about 200x20 cells filled.
So does anyone know how to solve this? A way to force the range to a certain size, like the size o rows from the datatable.
Thank you, any extra information just ask.
Added by request in answer:
Here is the method used to export the datatable to excel
private void exportExcel(DataTable data)
{
XLWorkbook wb = new XLWorkbook();
IXLWorksheet sheetSave = wb.Worksheets.Add(data, "list");
DialogResult saveDialogResult = saveFileDialog1.ShowDialog();
if ((saveDialogResult == DialogResult.OK) && (saveFileDialog1.FileName != null))
{
wb.SaveAs(saveFileDialog1.FileName);
}
}
After further searching\debugging I found I was setting the datatype in another method for the column and not for the cells used. So all the cells from row(1) to row(1058576) were being filled. Got the solution here. Thank you all.