Excel删除行删除错误的行
此代码应该获取我指定范围内的所有行,并仅删除其中没有单元格数据的行。它实际上删除了范围内的每一行。为什么?
Range range = _sheet.get_Range("A25:A542", Type.Missing);
range = range.EntireRow;
range.Delete(Type.Missing);
This code is supposed to get all rows in the range that I specify, and delete ONLY the rows with no cell DATA in them. It's actually deleting every row in the range though. Why?
Range range = _sheet.get_Range("A25:A542", Type.Missing);
range = range.EntireRow;
range.Delete(Type.Missing);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Type.Missing 并不意味着您认为的含义。 Type.Missing 是一个 COM 工件 - 它只是告诉 Excel 对象您没有提供该特定参数。这是 VB.NET 和 VBA 通常会为您处理的事情。 C# 4.0 支持可选参数,这使事情变得更加容易。
Type.Missing doesn't mean what you think it means. Type.Missing is a COM artefact - it just tells the Excel object that you're not providing that particular parameter. It's the kind of thing that's normally taken care of for you in VB.NET and VBA. C# 4.0 has support for optional parameters, which makes things much easier.
您不检查是否存在任何 DATA,因此程序会删除从第 25 行到第 542 行的所有行。
You do not check if any DATA exists, so the program deletes all rows from line 25 til line 542.