Hiding rows using EPPlus increases the size of the excel sheet created using EPPlus

Viewed 12

I am creating the new excel using EPPlus and I have requirement to keep specific no rows only to be editable and all other rows should be hidden(gray out) so user should not be able add any more rows. So we have write the code to hide rows i.e

wksht.Rows[lastRow + 1, 1048576].Hidden = true; (1048576 is the max limit for xlsx)

Due this one line of code, the size of the file becomes to heavy 2 to 3 megabyte, depending on the no of editable rows created.

Can someone please help us to resolve this issue?

1 Answers

When you set the rows to hidden, you are effectively editing a property of each of those rows, which in turn adds up to the data stored in the sheet.

Is it necessary to keep the hidden rows in the sheet for future modifications?

If you don't need them, why not just delete the empty rows?

for(int row = lastRow + 1; row <= 1048576; row++)
{
    wksht.DeleteRow(row);
}

In future if you need more rows, just insert new ones using this:

public void InsertRow(int rowFrom, int rows)

This way you can save those additional space.

Related