[英]How to determine which cells in a merged range are visible and can have a value?
I need to find out which Cells
of a Range
are not visible in ranges which are merged. 我需要找出合并范围内哪些Range
Cells
不可见。 I need to include empty cells but I want to exclude cells that are not visible as a result of merging cells. 我需要包含空单元格,但我想排除由于合并单元格而看不到的单元格。 (Only one cell, row, column in a merged range can contain a non empty value...?). (在合并范围内,只有一个单元格,行,列可以包含一个非空值...?)。
I have a following code: 我有以下代码:
using (XLWorkbook wb = new XLWorkbook(ExcelFile.FullName))
{
foreach (IXLNamedRange r in wb.NamedRanges)
{
foreach (var c in r.Ranges.Cells())
{
if (c.IsMerged() /*&& something*/)
continue;
/*Do processing of visible values*/
I need to get visible cells from merged ranges that would contain values if the value is filled in, ie without using IsEmpty()
. 我需要从合并范围中获取可见的单元格,如果值被填充,合并范围将包含值,即不使用IsEmpty()
。 I can determine, if the range is merged, but how can I add a condition to include only visible cells? 我可以确定范围是否已合并,但是如何添加条件以仅包括可见单元格? Is it always the first column/row? 它总是第一列/行吗? IsMerged()
returns true
on all cells in a merged range not only on those that are not visible and cannot contain a value. IsMerged()
在合并范围内的所有单元格上不仅返回不可见且不能包含值的单元格,还返回true
。
Example problem: 问题示例:
A named range has the address C21:D33. 命名范围的地址为C21:D33。 I need values of C21:C33 but I do not need to include values D21:D33 - they are all always null. 我需要C21:C33的值,但我不需要包含值D21:D33-它们都始终为null。 But the values of C21:C33 can also be null or empty, but I need them all. 但是C21:C33的值也可以为null或为空,但我都需要它们。 D21:D33 cannot contain anything else but null, but C21:C33 can contain a non null value. D21:D33只能包含null,但不能包含其他任何内容,但是C21:C33可以包含非null值。 I need all the cells that can be non empty. 我需要所有可以为非空的单元格。
This code finds the cells C21:C33
: 此代码找到单元格C21:C33
:
using (var wb = new XLWorkbook("test.xlsx"))
{
var nr = wb.NamedRange("MyRange");
foreach (var range in nr.Ranges)
{
var cellsToFind = range.Cells(c => c.MergedRange().FirstCell() == c);
Console.WriteLine($"{cellsToFind.First().Address}:{cellsToFind.Last().Address}");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.