//Need to update Excel sheet columns while retrieving data from data table enter code here
foreach (DataRow datarow in dt.Rows)
{
int[] colNumber = new int[] { 9,5,13,24,111,17,76,34,38 };
rowcount += 1;
for (int i = 0; i < colNumber.Length; i++)
{ string value = datarow[i].ToString();
ws.Cells[rowcount, colNumber[i]] = value;
}
}
The problem will not be solved by using EntityFramework as I'm afraid you are focusing on the wrong area. The main reason for this delay is that you are trying to access the worksheet object for each record in dt.Rows
.
I recommend using GemBox.Spreadsheet for this purpose. You can directly attach the datatable to the worksheet. Also, you don't need to explicitly convert values to string.
----------
// Code sample.
private void Download()
{
DataTable datatable=yourDatatable;// callStore Procedure to fetch DataTable
ExcelFile csvFile = new ExcelFile();//GemBox.Spreadsheet ExcelFile
ExcelWorksheet ws = csvFile.Worksheets.Add("YourWorkSheetName");
if (ws != null)
{
ws.InsertDataTable(datatable, 0, 0, true);
// Use MemoryStream to save or to send it to client as response.
}
}
----------
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.