1

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

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++;
}

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. I am using epplus latest nuget (4.1.0) on .Net 4.6.2 in C#

JP Hellemons
  • 5,977
  • 11
  • 63
  • 128

2 Answers2

1

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.

Fruchtzwerg
  • 10,999
  • 12
  • 40
  • 49
1

To anyone looking for this 4 years later: for some reason, resizing a row that contains an image slows things significantly. For efficiency, calculate and set the rows heights before adding the images. You will likely need to add the rows with all of their text information, with string.Empty cells where the images will go, and then add them after setting heights for the rows.