gpt4 book ai didi

c# - 如何在特定位置将文本添加到Word文档中?

转载 作者:太空狗 更新时间:2023-10-29 18:36:04 24 4
gpt4 key购买 nike

如何写入Word文档中的特定位置,例如第5行第50个字符?我已经搜索了几个小时,但找不到解决方案。

我正在使用 Microsoft.Office.Interop.Word

最佳答案

如果您对更简单的句子而不是台词感到满意:

ActiveDocument.Sentences(1).Characters(5).Select
Selection.Collapse
Selection.InsertBefore "added "

VBA 中的 5 个段落和 50 个空格

Selection.Text = String(5, vbCrLf) 
Selection.Collapse wdCollapseEnd
Selection.Text = String(50, " ")

但是,对于特定位置,我更喜欢文本框:

Set sh = doc.Shapes.AddTextbox(1, 10, 344, 575, 80)
sh.Name = "Course1"

具有一些属性:

sh.Fill.Visible = False
sh.Line.Visible = False
sh.TextFrame.MarginLeft = 0#
sh.TextFrame.MarginRight = 0#
sh.TextFrame.MarginTop = 0#
sh.TextFrame.MarginBottom = 0#

关于c# - 如何在特定位置将文本添加到Word文档中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12071425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com