在Word文档中使用C#替换占位符文档、Word

2023-09-04 02:41:10 作者:永远有多远i

我在字(.DOCX)格式的模板,并希望更换此模板的一些占位符用我自己的数据,你知道我在哪里可以找到合适的课程这个项目?这将是很好,我知道的命名空间。是否有处理word文档中的docx格式(XML),比COM类的任何新的班?谢谢你所有的答案,我希望有人能帮助我与我的问题。

I have a template in word (.docx) format and want to replace some placeholders in this template with my own data, do you know where I can find the right classes for this project? It would be nice for me to know the namespace. Are there any newer classes for handling word documents in the docx format (xml) than the com classes? Thank you for all your answers, I hope someone can help me with my problem.

映入眼帘

塞巴斯蒂安

推荐答案

新的Office格式(DOCX,XLSX,等等)是包含XML文件的集合zip文件。考虑到这一点,你有一对夫妇的方法。

The new office formats (docx, xlsx, etc) are zip files that contain a collection of xml files. With that in mind you have a couple of approaches.

您可以使用位于http://www.microsoft.com/downloads/details.aspx?FamilyId=AD0B72FB-4A1D-4C52-BDB5-7DD7E816D046&displaylang=en

您可以解压的docx文件,做一个搜索和替换为您的令牌和邮政编码,它回来了。

You can unzip the docx file, do a search and replace for your tokens, and zip it back up.

有一个网站 openxmldeveloper.org ,这只是对这种事情。另外,请记住,他们已经开始发售的SDK的Beta 2版本。

There is a website at openxmldeveloper.org that is just for this kind of thing. Also, bear in mind that they are already shipping a beta version 2 of the SDK.