c# - VSTO 合并单元格

标签 c# excel vsto oledb

在 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/

相关文章:

vsto - 如何确定占位符正在使用中?

c# - "correct"创建没有后台服务的 .NET Core 控制台应用程序的方法

c# - 访问当前的 RouteContext

vba - 如何在 excel 2016 中进行图像 url 验证?

python - 将不同列的不同格式的 pandas DataFrame 写入 Excel

excel - 如果不在两个值之间且不为空白,则更改单元格的背景颜色

VBA Excel UDF保留原始值

excel - VSTO - Word 和 Excel 的共享插件以修改功能区

c# - 使用 MVC 为 View 中 foreach 循环内的表生成随机 ID

c# - MsSql服务器:running stored procedure