使用 VSTO 删除 Word 2007 中段落后的间距

发布于 2024-08-21 16:29:17 字数 645 浏览 5 评论 0原文

我正在用 C# 创建并填充 Word 2007 表。当我在 Word 中查看结果时,每个单元格的文本后面都附加了额外的垂直空间。在Word中可以通过“页面布局”/段落/间距来调整,其中初始值为10pt。

---------------------------------------------------
| Text...     | Text....  | More text...          |
|             |           |                       | <- Extra spacing
---------------------------------------------------
|             |           |                       |

如何使用 VSTO 更改此设置?

我尝试录制一个宏,希望在VB代码中得到一些答案 - 它似乎没有响应间距值的变化。

我在 MSDN 上的 VSTO 文档中找不到任何相关内容。

编辑: 使用 Word 模板,我可以标记要填充的区域并将间距设置为 0。然后它会通过我的表格继承 - 因此它现在可以使用。不过,如果能够通过 C# 控制间距而不依赖于 Word 中的继承,那就太好了。

I am creating and populating a Word 2007 table in C#. When I view the result in Word, each cell has extra vertical space appended after the text. In Word this can be adjusted through the "page layout"/Paragraph/Spacing, where the initial value is 10pt.

---------------------------------------------------
| Text...     | Text....  | More text...          |
|             |           |                       | <- Extra spacing
---------------------------------------------------
|             |           |                       |

How can this be changed using VSTO?

I have tried to record a macro, hoping for some answers in the VB code - it didn't seem to respond to the changing of the spacing value.

I haven't been able to find anything related in the VSTO documentation on MSDN.

Edit:
Using a Word template, I can mark the area I'm populating and set the spacing to 0. It is then inherited through my table - thus it works for now. But still, it would be nice to be able to control the spacing from C# and not rely on inheritance in Word.

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

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

发布评论

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

评论(3

表情可笑 2024-08-28 16:29:17

根据 Jose Anton Bautista 的说法,解决方案如下所示:

Word.Document currentDocument;
currentDocument.Paragraphs.SpaceAfter = 0;

或者

Word.Table table;
table.Range.Paragraphs.SpaceAfter = 0;

这非常有效,对我来说,它显示了我还可以访问文档元素的各种属性的位置。

According to Jose Anton Bautista the solution is like the following:

Word.Document currentDocument;
currentDocument.Paragraphs.SpaceAfter = 0;

Or

Word.Table table;
table.Range.Paragraphs.SpaceAfter = 0;

This works very well and to me, it shows where I also can access various properties of the document elements.

诗笺 2024-08-28 16:29:17

我使用内置样式“表格网格”来删除单元格中的段落间距样式(Word 2007 默认情况下,“插入”>“表格”使用相同的样式):

Word.Document Doc = Globals.ThisDocument.Application.ActiveDocument;
Word.Table WordTable = Doc.Tables.Add(curSel.Range, 8, 5, ref missing, ref missing);

//Table Style
object tableStyle = "Table Grid";
WordTable.set_Style(ref tableStyle);

I've used the built-in style "Table Grid" to remove the paragraph spacing style in the cells (The Word 2007 default, Insert > Table uses the same style):

Word.Document Doc = Globals.ThisDocument.Application.ActiveDocument;
Word.Table WordTable = Doc.Tables.Add(curSel.Range, 8, 5, ref missing, ref missing);

//Table Style
object tableStyle = "Table Grid";
WordTable.set_Style(ref tableStyle);
做个ˇ局外人 2024-08-28 16:29:17

您还可能需要设置 LineSpacingRule

myTable.Range.Paragraphs.LineSpacingRule = WdLineSpacing.wdLineSpaceSingle;

Also you may need to set LineSpacingRule

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