Epplus行高问题 [英] Epplus row height issue

查看:512
本文介绍了Epplus行高问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个超过1000行的Excel文件.每行包含一些数据和2张图像. 图像以OfficeOpenXml.Drawing.eEditAs.OneCell

I have an excel file with over 1000 rows. Each row contains some data and 2 images. The images are attached as OfficeOpenXml.Drawing.eEditAs.OneCell

在填充Excel之后,我运行它来设置行高.

After populating the Excel I run this, to set the row height.

int prodTableStart = 3;
int prodTableEnd = 1025;

while (prodTableStart <= prodTableEnd)
{
    ws.Row(prodTableStart).Height = 112d; // works, but mega slow
    prodTableStart++;
}

我试图加快以下速度:ws.Cells["A" + prodTableStart + ":L" + prodTableEnd].Rows,但是返回了int? 那么如何在选定的行范围内设置行高效率呢?

I tried to speed up with something like this: ws.Cells["A" + prodTableStart + ":L" + prodTableEnd].Rows but that returns an int? So how can I set the row height efficient on a selected range of rows?

当我有很多行时,它甚至永远都不会结束.没有异常被抛出.该过程将永远持续下去.

When I have so many rows, it even never ends. No exception is thrown. The process just takes for ever.

ps.我在C#中使用.net 4.6.2上的epplus最新nuget(4.1.0)

ps. I am using epplus latest nuget (4.1.0) on .Net 4.6.2 in C#

推荐答案

在EPPlus中设置行高确实很慢.您可以像这样快速设置所有行的行高,而不是一一更新多个行的行高:

Setting the row height in EPPlus can be really slow. Instead of updating the row height of multiple rows one by one, you can set the row height for all rows very fast like:

workSheet.DefaultRowHeight = 500;

如果您不想设置所有行高,现在可以将行高一一设置回这些行的先前默认值. 如果需要更新高度的行比不需要更新高度的行多,此解决方案会更快.

If you don't want to set all row heights you now can set back the row height to the previous default value of these rows one by one. This solution is faster if the rows the height needs to be updated are more than the rows the height not needs to be updated.

这篇关于Epplus行高问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆