开发者

Excel delete rows deleting wrong rows

This code is supposed to get all rows in the range that I specify, and delete ONLY the rows with no cell DATA开发者_如何学C 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);


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.


You do not check if any DATA exists, so the program deletes all rows from line 25 til line 542.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜