复制带有合并单元格的Excel范围为单词表 - 这是一个错误,如何解决?

发布于 2025-01-21 12:18:23 字数 756 浏览 5 评论 0原文

在我的单词加载项(VSTO,vb.net)中,我从/导出到Excel和合并的单元格中构建了一个导入,这给了我悲伤。我当前的环境是Win11/64位Office365。我还没有能够在任何其他环境上进行测试。

进口商功能基本上确实在Excel中复制并在Word中可以复制,例如:

excelRange.Copy
wordRange.PasteExcelTable (false, false, false)

问题:当Excel范围垂直合并的单元格时,糊剂后的Word在表的右边包含了Rogue cellim,如您在表中的右侧所示。下图(第一列是Excel的源表,中间列中的结果。)。

我已经构建了一个小表解析程序,以告诉我每个单元格的行/列索引和宽度,结果很奇怪。请参阅下图中的第三列。我已经使用5种不同的表布局进行了测试。当我手动复制/粘贴时,这种行为也会发生。

流氓细胞在垂直合并的细胞的右侧显示。在第一个示例中,第3和4行。第5和6行上也有一些流氓细胞。基本上,这些流氓细胞是从垂直合并的行中添加到桌子末端的。

我可以构建一个例程以纠正Word中的粘贴表,但我试图了解正在发生的事情,以便将其纳入我的校正例程中。

你能给我任何想法或指示吗?谢谢!

In my Word add-in (VSTO, vb.net) I built a import from/export to Excel and merged cells is giving me grief. My current environment is Win11/64 bit Office365. I've not yet been able to test on any other environment.

The importer function basically does copy in Excel and PasteExcelTable in Word like so:

excelRange.Copy
wordRange.PasteExcelTable (false, false, false)

The problem: When the Excel range has vertically merged cells then Word after paste has included rogue cells to the right of the table as you can see in the middle column of the picture below (1st column is the source tables from Excel, middle column the results in Word.).

I've built a little table parser routine to tell me the row/column index and width of each cell and the results are weird. See the 3rd column in the picture below. I've tested with 5 different table layouts. This behaviour also happens when I manually copy/paste.

The rogue cells show to the right of the vertically merged cells. In the 1st example, rows 3 and 4. There are also some rogue cells on rows 5 and 6. Basically these rogue cells are added from the vertically merged rows until the end of the table.

I can build a routine to correct the pasted table in Word but I am trying to understand what is happening so I can factor that into my correction routine.

Can you give me any ideas or pointers? Thanks!
Comparing Excel source and Word result

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

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

发布评论

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

评论(1

全部不再 2025-01-28 12:18:23

我在VSTO ADDIN中也有类似的问题。
我想出的唯一一件事是计算Excel表中的合并单元格并将其写入数组。然后,我尝试将单元中的单元格合并,但是当您将单词合并时,列计数已移动。您需要计算转移柱以纠正合并单元格。

I have similar issue in my VSTO addin.
The only thing I came up with that is counting the merged cells inside an Excel sheet and writing them to an array. Then i tried to merge cells in Word, but when you merging cell in Word, columns count have been shifted. You need to calculating shifting columns to correct merging cells.

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