Office Interop Word c#.net:在特殊位置复制表格

发布于 2024-08-11 04:50:27 字数 504 浏览 3 评论 0原文

我目前正在使用 Interop 处理 Word 模板中的表格。

在我的模板中,我有一个要复制的表格(复制将使我更容易填写数据而不是插入行和列,因为模板有很多写入格式)。 新表应插入到原始表的正下方。最好的是它们看起来像一张桌子。

我的问题是我在两个表之间有一个段落。我怎样才能避免这种情况?

这是我的代码:

object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
Word.Range rng = table.Range;
rng.Collapse(ref oCollapseEnd);

Word.Table tableCopy = document.Tables.Add(rng, 1, 1, ref missing, ref missing);
table.Range.Copy();
tableCopy.Range.Paste();

Clipboard.Clear();

任何帮助将不胜感激! :)

I'm currently working on tables in a Word template with Interop.

In my template I have a table which I want to copy (Copying will make it easier for me to fill in the data rather than inserting rows and column, because the template has a lot of write formatting).
The new table should be inserted right under the original table. The best would be that they would look like one single table.

My problem is that I get a paragraph between the two tables. How can I avoid this?

Here is my code:

object oCollapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
Word.Range rng = table.Range;
rng.Collapse(ref oCollapseEnd);

Word.Table tableCopy = document.Tables.Add(rng, 1, 1, ref missing, ref missing);
table.Range.Copy();
tableCopy.Range.Paste();

Clipboard.Clear();

Any help would be very appreciated! :)

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

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

发布评论

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

评论(1

不一样的天空 2024-08-18 04:50:27

因此,我们对这个问题进行了更多研究并找到了解决方案。我想只有我对范围的东西感到困惑。只是觉得我应该发布它。 :)

Word.Range range = table.Range;
range.Copy();

Word.Range rng = table.Range;
rng.SetRange(table.Range.End, table.Range.End);

Word.Table tableCopy = document.Tables.Add(rng, 1, 1, ref missing, ref missing);
tableCopy.Range.Paste();

// got an extra row for some reason -> need to delete it
table.Rows[table.Rows.Count].Delete();

So, was working more on this issue and found a solution. Guess it was just me that got confused about the range stuff. Just thought i should post it. :)

Word.Range range = table.Range;
range.Copy();

Word.Range rng = table.Range;
rng.SetRange(table.Range.End, table.Range.End);

Word.Table tableCopy = document.Tables.Add(rng, 1, 1, ref missing, ref missing);
tableCopy.Range.Paste();

// got an extra row for some reason -> need to delete it
table.Rows[table.Rows.Count].Delete();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文