如何检测包含(水平)合并单元格的 Word 表格?

发布于 2024-10-09 15:52:52 字数 290 浏览 1 评论 0原文

当 Word 表格包含水平合并的单元格时,访问 aTable.Columns.First 或对 aTable.Columns 执行 For Each 将导致错误。

有没有办法确定表格是否包含水平合并的单元格而不导致错误?

我已阅读确定 Word 单元格是否合并,但是是关于检测特定的 Word 表格单元格是否被合并,而不是整个表格是否有任何合并的单元格。

When a Word table contains horizontally merged cells, accessing aTable.Columns.First or performing a For Each over aTable.Columns will result in an error.

Is there a way to determine if a table contains horizontally merged cells without resulting in an error?

I've read Determine if a Word cell is merged, but that is about detecting if a particular Word table cell is merged, rather than does the whole table have any merged cells.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾旎 2024-10-16 15:52:52

本文中找到了对 Table 对象上的 Uniform 属性的引用,该属性将返回 false if该表已合并或拆分单元格。

虽然这并不表明单元格是水平合并还是垂直合并(或两者兼而有之),但这是一个开始,该属性回答了我的问题。

Found a reference in this article to a Uniform property on the Table object, which will return a false if the table has merged or split cells.

Though this does not indicate if the cells are horizontally or vertically merged (or both), but it's a start, and the property answers my question.

情泪▽动烟 2024-10-16 15:52:52

是的,它就在那里。
这是如何检测垂直合并单元格的逻辑解释。水平合并的单元格也可以检测,但需要更多的编码。

            But, unfortunately, not by calling any WORD VBA method or accessing any property of cell or table. It's by applying successive steps.

            Step1:
            -> Detect Row Count and Column Count of the table

            Step2:
            -> Declare an string array with same dimension as table( Dim A$()). Fill each cell of the array with "<m>" string.

            Step3:
            -> Start from cell(1)
            -> Then move cell by cell(Cell.Next method)
            -> Get each cells RowIndex and ColumnIndex.
            -> Erase the content "<m>" from the array, referenced by this RowIndex and ColumnIndex(A(RowIndex,ColumnIndex)=""
            -> Repeat this step until Cell.Next ends.

            Step4:
            -> Now check each cell of the Array(A$()). Those cells have the"<m>" string, are merged. Merged with immediate top cell. 

            I've not placed any function or code block. Assume it'll be more easy.

            Thanks

            Shubhayan

Yes, it's there.
Here is the logical explanation how you will detect vertically merged cells. Horizontally merged cell also can detect, but it will need some more coding.

            But, unfortunately, not by calling any WORD VBA method or accessing any property of cell or table. It's by applying successive steps.

            Step1:
            -> Detect Row Count and Column Count of the table

            Step2:
            -> Declare an string array with same dimension as table( Dim A$()). Fill each cell of the array with "<m>" string.

            Step3:
            -> Start from cell(1)
            -> Then move cell by cell(Cell.Next method)
            -> Get each cells RowIndex and ColumnIndex.
            -> Erase the content "<m>" from the array, referenced by this RowIndex and ColumnIndex(A(RowIndex,ColumnIndex)=""
            -> Repeat this step until Cell.Next ends.

            Step4:
            -> Now check each cell of the Array(A$()). Those cells have the"<m>" string, are merged. Merged with immediate top cell. 

            I've not placed any function or code block. Assume it'll be more easy.

            Thanks

            Shubhayan
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文