简体   繁体   English

在C#和ASP.net中处理Word文档

[英]Manipulate word document in C# and ASP.net

I want a way to manipulate a word document. 我想要一种操作Word文档的方法。 The document is a word template .DOTX file, and I need to hide and/or show specific paragraphs of the document based on conditions on my ASP.NET/C# application. 该文档是Word模板.DOTX文件,我需要根据ASP.NET/C#应用程序上的条件隐藏和/或显示文档的特定段落。

For example, if i entered the first and last names in my form, the generated word doc will show both fields, else of the last name is not entered it will not be shown in the generated document. 例如,如果我在表单中输入了名字和姓氏,则生成的单词doc将显示两个字段,否则未输入姓氏的文件将不会显示在生成的文档中。 I already know how to generate the doc but I dont know how to hide and/or show specific elements. 我已经知道如何生成文档,但是我不知道如何隐藏和/或显示特定元素。

I am using Docentric Toolkit for this kind of scenario. 我在这种情况下使用Docentric Toolkit。 The toolkit itself is using OpenXML in the background, so no Word installation is necessary. 该工具包本身在后台使用OpenXML,因此无需安装Word。 I suggest you take a look at the example for conditional content here . 我建议您在这里看看有条件内容的示例。

In your ASP.NET application you prepare a data model. 在ASP.NET应用程序中,您准备一个数据模型。 This model should also include a boolean field where you set true/false value depending on whether you want to show conditional content in the document or not. 该模型还应该包括一个布尔字段,您可以在其中设置true / false值,这取决于您是否要在文档中显示条件内容。 The document template contains conditional tag, which is used as a placeholder for conditional content. 文档模板包含条件标签,该标签用作条件内容的占位符。 Other tags (placeholders) can be nested in conditional content. 其他标签(占位符)可以嵌套在条件内容中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM