简体   繁体   English

Excel SpecialCells(xlCellTypeBlanks)合并单元格失败

[英]Excel SpecialCells(xlCellTypeBlanks) fails with merged cells

Excel SpecialCells(xlCellTypeBlank) includes all cells in a merged range, regardless of whether they are blank. Excel SpecialCells(xlCellTypeBlank)包括合并范围内的所有单元格,无论它们是否为空白。 I consider this to be a bug, and I desperately need a workaround. 我认为这是一个错误,我迫切需要一种解决方法。 Steps to duplicate: 复制步骤:

(1) Create a worksheet with some text in cells A1 and B3. (1)在单元格A1和B3中创建带有一些文本的工作表。 Now activesheet.usedrange.cells.count = 6 and activesheet.usedrange.specialcells(xlcelltypeblanks).cells.count = 4 These values are as expected. 现在activesheet.usedrange.cells.count = 6和activesheet.usedrange.specialcells(xlcelltypeblanks).cells.count = 4这些值与预期的一样。

(2) Now merge cells A1:A2, and activesheet.usedrange.cells.count = 6 and activesheet.usedrange.specialcells(xlcelltypeblanks).cells.count = 5 Both A1 and A2 are now considered blank. (2)现在合并单元格A1:A2,并合并activesheet.usedrange.cells.count = 6和activesheet.usedrange.specialcells(xlcelltypeblanks).cells.count = 5现在将A1和A2都视为空白。

I need to find a way to select just cells A3, B1, and B2 in this case. 在这种情况下,我需要找到一种仅选择单元格A3,B1和B2的方法。 I'm actually doing this using .NET Excel Interop, so I do not want to have to actually retrieve the cell value as a part of the test, since this is a huge performance penalty in Excel Interop; 我实际上是使用.NET Excel Interop进行此操作的,因此,我不想在测试中实际获取单元格值,因为这在Excel Interop中会造成巨大的性能损失; so I'm restricted to an internal cell selection function such as SpecialCells. 因此我只能使用内部单元选择功能,例如SpecialCells。

I got this to work by selecting smaller ranges at various places in the code, usually just before doing any cell merging. 通过在代码的各个位置选择较小的范围(通常在进行任何单元合并之前),我可以使用此方法。 I consider this to be a workaround, not really a solution. 我认为这是一种解决方法,而不是真正的解决方案。 Thanks to those who commented - you helped inspire this workaround. 感谢那些发表评论的人-您帮助启发了这种解决方法。

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

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