简体   繁体   English

使用 EPPlus 隐藏行会增加使用 EPPlus 创建的 excel 工作表的大小

[英]Hiding rows using EPPlus increases the size of the excel sheet created using EPPlus

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.我正在使用 EPPlus 创建新的 excel 并且我要求保持特定的无行仅可编辑,并且所有其他行都应隐藏(灰色),因此用户不应再添加任何行。 So we have write the code to hide rows ie所以我们编写了隐藏行的代码,即

wksht.Rows[lastRow + 1, 1048576].Hidden = true; wksht.Rows[lastRow + 1, 1048576].Hidden = true; (1048576 is the max limit for xlsx) (1048576 是 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.由于这一行代码,文件的大小变成了 2 到 3 兆字节,具体取决于创建的可编辑行的数量。

Can someone please help us to resolve this issue?有人可以帮我们解决这个问题吗?

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.这样您就可以节省这些额外的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM