c# - 将数据表与公式绑定时的 C# ReoGrid 性能问题
问题描述
当数据表中有 150 列和 4000 行时,我已经用随机值和公式(如=SUM(A1:A2))填充了我的数据表, 然后 ReoGrid 需要大约 20 分钟才能填充。
当我在没有公式的情况下填充 ReoGrid 时,填充 ReoGrid 需要几秒钟,但是当许多 SUM 公式被动态分配给单元格时,ReoGrid 需要很长时间才能填充。
在这里我分享我的代码。所以我的请求请大家看看我的代码逻辑并告诉我在将公式分配给 ReoGrid 的许多单元格时是否有任何缺陷。
请告诉我如何简化用公式填充网格的逻辑。有没有办法用公式来提高我的代码的性能,结果 ReoGrid 可以在几秒或几分钟内填充。
寻找建议和指导方针。ReoGrid 是 winform 应用程序https://reogrid.net/的免费组件。
这是我的代码
private void btnBindTable_Click(object sender, EventArgs e)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string strSum = "", strColName, strImmediateOneUp = "", strImmediateTwoUp = "";
int startsum = 0;
int currow = 0;
bool firstTimeSum = true;
int NumRows = 4000;
int NumColumns = 150;
var sheet = reoGrd.CurrentWorksheet;
sheet.Resize(NumRows, NumColumns); // resize
DataTable dt = new DataTable();
for (int col = 0; col < NumColumns; col++)
{
strColName = GenerateColumnText(col);
DataColumn datacol = new DataColumn(strColName, typeof(string));
dt.Columns.Add(datacol);
}
for (int row = 0; row < NumRows; row++)
{
dt.Rows.Add();
for (int col = 0; col < NumColumns; col++)
{
if (row < 2)
{
dt.Rows[row][col] = new Random().Next(1, NumRows).ToString("D2");
}
else
{
if (firstTimeSum)
{
if (row - currow == 2)
{
currow = row;
startsum = 0;
firstTimeSum = false;
}
else
{
startsum = 1;
}
}
else
{
if (row - currow == 3)
{
currow = row;
startsum = 0;
}
}
if (startsum == 0)
{
strColName = GenerateColumnText(col);
strImmediateOneUp = strColName + ((row + 1) - 1).ToString();
strImmediateTwoUp = strColName + ((row + 1) - 2).ToString();
dt.Rows[row][col] = strSum;
string cellname = GenerateColumnText(col) + (row + 1).ToString();
var cell = sheet.Cells[cellname];
cell.Style.BackColor = Color.LightGoldenrodYellow;
}
else
{
dt.Rows[row][col] = new Random().Next(1, NumRows).ToString("D2");
}
}
}
startsum = 1;
}
sheet["A1"] = dt;
stopwatch.Stop();
TimeSpan timeSpan = stopwatch.Elapsed;
MessageBox.Show(string.Format("Time elapsed: {0}h {1}m {2}s {3}ms", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds));
}
解决方案
推荐阅读
- cocoa - 在 OSX 中通过 JNI_CreateJavaVM 启动 JVM 仅限控制台
- amazon-web-services - 我可以对其他 Amazon S3 IAM 用户隐藏用户文件夹吗?
- python - 微调 CNN 超参数以进行复杂的文本分类
- c# - How to add app icon to Xamarin Android app
- reactjs - 你能在商店更新时阻止其他 JSX 元素的 UI 更新吗?
- coq - 在 Coq 中将术语解释为类型
- python - 与按钮不同的列中的 Tkinter 包装条目
- php - TCPDF Y 位置正在重置
- mongodb - 猫鼬模式预方法中的打字稿错误:“this”意外别名为局部变量
- java - 用于计算在字符串 java 中找到元素出现次数的代码