How to Read .Doc Template File and Edit Template with Values?

梦想的初衷 提交于 2019-12-11 03:44:42

问题


I have a document template and I want to use that template for merging client information with that (Replacing <>, <> <> with our information from database.

To do this i first need to read the document, update the fields and then save it with tag replaced data.

Can any one please help me to visualize this; how to do this and using what tools?

Thanks, Jigar


回答1:


I found my answer from http://docx.codeplex.com/ tool. It is really super cool tool to do modification in your document template.

Consider this - with minimal efforts to make it ready for you.




回答2:


You will have to use OpenXML technology to manipulate the word document and insert dynamic content into the word document. I assume that you are using docx word documents for this purpose. The docx file is actually a zipped file which has many xml files, which inturn can be manipulated using the OpenXML API using c#. In your case, the contents of the word will be in an xml called "document.xml". You will have to read this XML and replace the <> placeholder with your data from database. I have written 2 articles (with source code) with respect to these concepts. You can use the following links which can give a heads-up.

http://www.codeproject.com/KB/office/Word_2007_Footnote.aspx http://www.codeproject.com/KB/office/Word_2007_Images.aspx

Though it might not give you the exact solution to the specific problem you have, you can use this to start off with something (like how to read the document.xml using OpenXML API and c#), and then you can work on your own to fix your problem.

EDIT: Did not notice you mentioned .doc file. I saw the OpenXML tag to it, hence replied. I guess this solution applies only if the document is .docx.




回答3:


You can try http://worddocgenerator.codeplex.com/. WordDocumentGenerator is an utility/samples to generate Word documents from templates using Visual Studio 2010 and Open XML 2.0 SDK.




回答4:


You may talk to an Aspose presale to see if the components help,

http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx

Besides, Microsoft SharePoint Server 2010 has Word automation services,

http://msdn.microsoft.com/en-us/library/ff742315.aspx

Don't try to use service side Office automation, as it is a dead end,

http://support.microsoft.com/kb/257757




回答5:


I believe you're looking for 'mail merge' feature for Word documents. Please see the help topics in the 'Mail Merge and Reporting' section of Aspose.Words for .NET documentation.

Disclosure: I work as a developer evangelist at Aspose.




回答6:


Docmosis is multi-platform tool that can use .doc file as templates and populate via a mail-merge like process. By default it uses document fields and in plain text the <<field>> notation.



来源:https://stackoverflow.com/questions/8877328/how-to-read-doc-template-file-and-edit-template-with-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!