What is the best way to populate a Word 2007 template in C #?

I need to fill out a Word 2007 document from code, including repeating table sections - I am currently using XML conversion in the document.xml part of the docx file, but it is very time-consuming to set up (every time you edit a template document, you need to recreate the transform file .xsl, which can take up to one day for complex documents).

Is there a better way, preferably one that does not require you to run Word 2007 during the process?

Relationship Richard

+6
c # ms-word word-2007 openxml docx
source share
5 answers

I tried writing code for this purpose, but gave up. Now I am using a third-party product: Recommend words and am satisfied with this component.

The computer does not require Microsoft Word.

"Aspose.Words allows .NET and Java applications to read, modify, and write Word® documents without using Microsoft Word®."

"Aspose.Words supports a wide range of functions, including document creation, content processing and formatting, powerful merging capabilities, comprehensive support for DOC, OOXML, RTF, WordprocessingML, HTML, OpenDocument and PDF formats. The most affordable, fast and multi-functional Word component on the market" .

DISCLAIMER . I am not affiliated with this company.

+3
source share

Since a DOCX file is just a ZIP file containing a folder structure with images and XML files, you should be able to manipulate these XML files using our favorite XML manipulation API. The format specification is known as WordprocessingML , part of Office Open XML .

I thought I mentioned this in case the third-party tool proposed by splattne is not an option.

+2
source share
+2
source share

Use invoke docx lib. It supports table data ( http://invoke.co.nz/products/help/docx_tables.aspx ). Additional information at http://invoke.co.nz/products/docx.aspx

+1
source share

Have you considered using VB? You can create a separate assembly to populate your document.

I know you're looking for a solution in C #, but XML literal support is one area where XML literal support can help you fill out the document. Create a document in Word on the server as a template, unzip the docx, paste the appropriate XML section that you want to change into your VB code, and add the code to fill in the parts you want to change. It’s hard to say from your description if this meets your requirements, but I would suggest exploring it.

0
source share

All Articles