如何在Word模板中替换文本或将文本插入书签 [英] How to replace text or insert text into bookmarks in a word template
本文介绍了如何在Word模板中替换文本或将文本插入书签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Word模板,它有一些文件,我需要填写从文本框输入的信息.该字段可以通过书签或< filedname>"来标识.我想要想要以特定字体和字体大小插入该文本.我怎样才能做到这一点?我需要一些示例代码,因为我是对此的新手.语言是C#.谢谢
I have a word template and it got some fileds that I need to fill with the information I enter form a TextBox. This fields can be identified by bookmarks or by "<filedname>". I wanna want to insert that Text in specific font and font size. How can I do that? I need some example code since I''m a newbie to this. The language is C#. Thanks
推荐答案
如果您获得了Word文档的模板,并希望通过一些数据(文本)来使用它,请使用 ^ ].
您可以在代码中进行操作(按照上面的链接),但是我想演示它的工作原理:
1)创建新文档
2)添加新的CustomDocumentProperty
(菜单文件->属性[书签:]非标准
a)名称:AAA1
b)类型:Text
c)值:"Some text
"
d)按下Add
和OK
按钮
3)将此属性插入文档(菜单插入"->字段"->"DocProperty",选择AAA1
,然后单击"OK
"按钮)
你看到什么了? "Some text
".右键单击它,您将看到文档字段的菜单.
以相同的方式,在添加CustomDocumentProperty时,可以对其进行更改.区别在于步骤2.而是添加,选择AAA1
属性并更改其值.
If you got the template of Word document and you want to feel it with some data (text), use CustomDocumentProperties[^].
You can do it in code (follow the above link), but i want to demonstrate how it works:
1) Create new document
2) Add newCustomDocumentProperty
(menu File->Propeties [bookmark:] Nonstandard
a) Name:AAA1
b) Type:Text
c) Value: "Some text
"
d) pushAdd
andOK
button
3) Insert this property into document (menu Insert->Field->DocProperty, chooseAAA1
, clickOK
button)
What you see? "Some text
". Right-click on it and you''ll see the menu for document-fields.
In the same way, as you add CustomDocumentProperty, you can change it. The difference is in step 2. Instead add, chooseAAA1
property and change it values.
这篇关于如何在Word模板中替换文本或将文本插入书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文