c# - 从数据表更新excel表列时需要避免数据表中5k条记录的延迟
问题描述
//从数据表中检索数据时需要更新Excel工作表列在此处输入代码
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;
}
}
解决方案
使用 EntityFramework 将无法解决该问题,因为恐怕您关注的是错误的区域。这种延迟的主要原因是您试图访问dt.Rows
.
为此,我建议使用 GemBox.Spreadsheet。您可以直接将数据表附加到工作表。此外,您不需要将值显式转换为字符串。
----------
// 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.
}
}
----------
推荐阅读
- rest - 如何在导入 swagger 文件后调用具有作用域的 WSO2 APIM 2.1 的 RESTful Store API?
- php - PHP cURL 不适用于 Xampp Windows 10
- wordpress - 如何更改默认 Wordpress 语言?
- .net-core - 使用 safari 和 Identity Server 4 登录时出现问题
- bitbucket-server - Stash 中的 mutableGroups 和 mutableDetails
- c# - 保持不变的错误级别的 C# 程序
- ios - 当应用程序在后台时,使用 URLSession 和操作队列下载不会开始下一个操作
- mysql - 重叠预订 SQL
- javascript - JavaScript 中特殊字符的人类可读版本
- ios - 导入框架与模块