[英]EPPLUS To Clear Contents of A Range Of Cells
I want to use EPPLUS to clear a range of cells. 我想用EPPLUS清除一系列细胞。 I tried the syntax below, but it gives me an error of
我尝试了下面的语法,但它给了我一个错误
object reference not set to an instance of an object
你调用的对象是空的
What would be the proper way to clear the contents of cells A24:C36 with EPPLUS? 用EPPLUS清除细胞A24:C36的内容的正确方法是什么?
ExcelPackage package = new ExcelPackage();
ExcelWorksheet ws = package.Workbook.Worksheets["Sheet1"];
ws.Cells["A24:C36"].Clear();
Your code is correct. 你的代码是正确的。 I think the
.xlsx
file does not have Worksheets
with Sheet1
name. 我认为
.xlsx
文件没有Sheet1
名称的Worksheets
。
For example, I created this excel file like this: 例如,我创建了这个excel文件,如下所示:
I wanted to erase A24:C36
. 我想擦掉
A24:C36
。 I encountered null reference
error before executing ws.Cells["A24:C36"].Clear();
我在执行
ws.Cells["A24:C36"].Clear();
之前遇到了null reference
错误ws.Cells["A24:C36"].Clear();
like this: 像这样:
If I use code below instead of it, it works properly ( Sheet2 ). 如果我使用下面的代码代替它,它可以正常工作( Sheet2 )。
ExcelPackage package = new ExcelPackage();
ExcelWorksheet ws = package.Workbook.Worksheets["Sheet2"];
ws.Cells["A24:C36"].Clear();
Notice that having no value in A24:C36
does not make an error. 请注意,在
A24:C36
中没有值A24:C36
不会出错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.