在 VSTO(/JET OLEDB 或其他读取 excel 文件的方法)中是否有任何方法可以判断数据是来自单个单元格还是合并的单元格范围并获取此范围?
最佳答案
此处最短的路径是使用 bool Range.MergeCells
属性。
假设您的单元格引用被命名为 myCell
,您可以使用如下内容:
if (myCell.MergeCells)
{
// The 'myCell' is part of a merged cell area.
}
Else
{
// The 'myCell' is not part of any merged cell area.
}
您还可以检查 Range.MergeArea
属性返回的范围上的 Cells.Count
:
if (myCell.MergeArea.Cells.Count > 1) {...}
或:
if (myCell.MergeArea.Count > 1) {...}
最后一个示例之所以有效,是因为 Range.Count 属性总是返回与 Range.Cells.Count 相同的值,这是设计使然。
关于c# - VSTO 合并单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1499698/