如何使用OpenXML构建自定义句子 [英] How to build custom sentences with OpenXML

查看:94
本文介绍了如何使用OpenXML构建自定义句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以播放" .docx中的句子.

这是我需要做的:

我在文档中有一个段落

我的段落示例: 这是一段,我需要根据某些条件设置 的格式,但我不知道如何使用openxml sdk进行格式化. 示例结束.

因此,根据我在C#中求值的条件,我想添加/删除文本.您还应该知道id的另一件事,我希望产品负责人更改文档的文本.

基本上我想要实现的是拥有一个模板文档,我的产品所有者可以随意编辑该模板文档,但是在此文档中,文本可能会根据生成文档的人而有所不同.

谢谢

解决方案

您可以在Word中创建模板文档,并在要动态插入文本的每个位置创建一个内容控件.对于每个创建的内容控件,您应该设置唯一的 Tag 属性值.

然后在您的c#应用程序代码中,可以非常容易地通过其标签找到内容控件.找到它之后,您可以保存其父节点,删除内容控件,然后将想要的文本作为先前保存的父节点的子段落元素插入.

您可以使用开发人员"选项卡添加内容控件.如果看不到它,则可以使用此处描述的步骤来显示它: http://msdn.microsoft.com/en-us/library/bb608625.aspx .

I would like to know if there is a way to "play" with sentences in a .docx.

Here's what I need to do:

I have a paragraph in a document

exemple of my paragraph: This is a paragraph that I need to format based on some conditions and I can't figure how to do this with openxml sdk. end of exemple.

So based on a condition that I evaluate in c# I would like to add/remove the text. Another thing that you should know id that I would like the product owner to change the text of the document.

Basicly what I want to acheive is having a template document that my product owner can edit at will but in this document the text might change based on for whom the document is produce.

Thanks

解决方案

You can create a template document in Word and create a content control in each place you want the text to be dynamically inserted. For each created content control, you should set unique Tag property value.

In your c# application code, you can then find a content control by its tag quite easily. After you find it, you can save its parent node, remove the content control and insert the text you want as a child paragraph element for the parent node saved earlier.

You can add content controls by using Developer tab. If you can't see it, you can use steps described here in order to show it: http://msdn.microsoft.com/en-us/library/bb608625.aspx .

这篇关于如何使用OpenXML构建自定义句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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