Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libraries to generate docx files (Open XML)

Tags:

c#

docx

We need to generate docx documents from an asp.net mvc site. The documents will vary a great deal, but they are pretty basic - the only thing out of the ordinary is the need to include tables. The c# code that generates the documents will need to create similar html/css as well. We don't have time to buy a commercial product for this.

Should we just read the spec and write some code to spit out the XML, or are there libraries available that would do the trick?

Edit: looks like Microsoft's Open XML library is an obvious choice, but does anyone have any experience with it? And can anyone point to some sample code that uses it?

like image 802
Old Man Avatar asked Mar 18 '11 18:03

Old Man


People also ask

Are DOCX files XML?

A Simple DOCX fileAll the files inside a DOCX are XML files, even those with the ". rels" extension.

How do I read XML files in Word?

#1) Open Windows Explorer and browse to the location where the XML file is located. We have browsed to the location of our XML file MySampleXML as seen below. #2) Now right-click over the file and select Open With to choose Notepad or Microsoft Office Word from the list of options available to open the XML file.

What is Open XML SDK?

The Open XML SDK 2.5 simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML SDK 2.5 encapsulates many common tasks that developers perform on Open XML packages, so that you can perform complex operations with just a few lines of code.


2 Answers

Try this... http://openxmlwriter.codeplex.com/

codeplex.com has a lot of other libraries too.

http://www.codeplex.com/site/search?query=openxml

like image 71
chkdsk Avatar answered Oct 03 '22 01:10

chkdsk


You can try https://github.com/open-xml-templating/docxtemplater

It makes it possible to create a template written in docx, that contains tags Hello {name} tha will be replaced.

You also have the possibility to create tables by looping over the table columns.

like image 33
edi9999 Avatar answered Oct 03 '22 00:10

edi9999