如何在特定位置的Word文档中添加文本? [英] How to add text into Word Documents at a specific position?

查看:121
本文介绍了如何在特定位置的Word文档中添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I write to a specific position in a Word document, for example, line 5, character 50? I have searched for a couple of hours, but couldn't find a solution.

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

推荐答案

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

If you are content with the more simple sentence, rather than lines:

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

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

Five paragraphs and 50 spaces in VBA

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

但是,对于特定位置,我希望使用文本框:

However, for a particular position, I would prefer a textbox:

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#

这篇关于如何在特定位置的Word文档中添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆