Aniket Narvankar

Aniket Narvankar

  • 538
  • 2.1k
  • 580.8k

Export very large data to Excel file

Jan 14 2019 3:44 AM
I want to write data into four sheets in single excel.I am facing problem,for large amount of data,it gives system out of memory exception
I have more than 300 columns and around 28000 rows in one table,there are total 4 tables.My application works fine for around 12000 rows,but throws  exception after this.
 
Is there any way this could be resolved,tried everything but not found any solution.Please do let me know about the same.
 
Here is my code which creates excel with 4 sheets
 
 
string AppLocation = ConfigurationManager.AppSettings["Path"].ToString();
string file = AppLocation + "\\DataFile.xlsx";
using (XLWorkbook wb = new XLWorkbook())
{
wb.AddWorksheet(ds.Tables[0],"Claim_register_Self_Funds_2015"); 
wb.AddWorksheet(ds.Tables[1],"Claim_register_Self_Funds_2016");
wb.AddWorksheet(ds.Tables[2],"Claim_register_Self_Funds_2017");
wb.AddWorksheet(ds.Tables[3],"Claim_register_Self_Funds_2018"); 
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
wb.SaveAs(file);
}
 

Answers (4)