我使用此代码将数据加载到工作表(C,EPPLUS 4.04)中,并自动设置列宽:

workSheet.Cells["A1"].LoadFromCollection(itemsToExport, PrintHeaders: true);
workSheet.Cells[workSheet.Dimension.Address].AutoFitColumns();

对于工作表中的记录数,有一个明显的性能惩罚似乎是线性的。例如,15K记录上的2秒差异,我必须创建多个文件。
有没有办法在不使用异步处理等方法的情况下加快速度?
注意,在填充数据之前设置autofitcolumns不起作用,列的宽度对于数据来说太小。

最佳答案

罗恩·拜尔的评论是对的。我从epplus.codeplex.com下载了源代码并查看了函数:

/// <summary>
/// Set the column width from the content of the range.
/// Note: Cells containing formulas are ignored if no calculation is made.
///       Wrapped and merged cells are also ignored.
/// </summary>
/// <param name="MinimumWidth">Minimum column width</param>
/// <param name="MaximumWidth">Maximum column width</param>
public void AutoFitColumns(double MinimumWidth, double MaximumWidth)

不幸的是,所有的细胞都会被循环处理。也许我应该使用像Courier这样的等距字体,自己计算宽度。
EPPLUS库中的AutoFixStudio可以使用一些额外的注意,因为它的代码复杂度为35个大气压(但保持良好的工作状态)!是的。

关于c# - 自动色谱柱宽度EPPlus慢,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32075037/

10-13 06:48