Ayende @ Rahien

Unnatural acts on source code

Looking for Word & Excel documents generation

I need to generate Excel & Word documents from my application. I took a look at some of the stuff that is out there, but I couldn't really find anything that was immediately useful. What I need is basically:

  • The ability to create the documents
  • Styles (colors, images, etc)
  • Templates are preferred

This is something that running on my server, so using the Office COM objects is not possible. In general, I am looking for something that would be easy to use for generating a document with styles, nothing more.

Obviously I would preferred if it was an OSS solution, but I am not fanatic about that.

Any suggestions?

Comments

Noone
06/12/2007 07:15 PM by
Noone

http://www.infoq.com/news/2007/06/OpenXML-Libraries

Michael
06/12/2007 08:11 PM by
Michael

Our company is using these components: http://www.aspose.com/

$8K for a site license but a lot of functionality and easy to use.

HakonB
06/12/2007 08:57 PM by
HakonB

Have a look at http://www.codeplex.com/ExcelPackage for generating Excel files.

Trevor
06/12/2007 08:59 PM by
Trevor

Definetly look into using open xml. Microsoft added the System.IO.Packaging namespace to .Net 3.0 and has just released a SDK as a CTP. Also there is a great community site here: http://openxmldeveloper.org

If your docs will be opened in office 2000/XP/2003 then you'll need to install the compatibility pack but that is available as a free patch from microsoft.

Bobby Diaz
06/12/2007 09:16 PM by
Bobby Diaz

There is always the low-tech method of generating HTML and changing the Response.ContentType to that of the application you want the result to open with. I have used this for both a generic search results export to excel as well as for custom excel reports with images and formatting.

Ben
06/12/2007 09:59 PM by
Ben

using Apache POI in conjunction with IKVM. Here an example with IKVM and Apache FOP:

http://www.onjava.com/pub/a/onjava/2004/08/18/ikvm.html

Kevin McDonnell
06/12/2007 11:43 PM by
Kevin McDonnell

For Word, I've used RTF creation but it's pretty awkward and gets very very fiddly. Best way is definitely the OpenXML. I've used it with Excel without too many problems and this was using Excel 2003 so I'm hoping 2007 would be much better.

Apolon
06/13/2007 12:58 AM by
Apolon

For Excel, I've used Syncfusion's XlsIo and it works really well. No hassles and fast: http://www.syncfusion.com/products/xlsio/windows/default.aspx

On the Word side I've used Tx Text Control: http://www.textcontrol.com. It works but the API seems clunky to me. It would be worth giving the Syncfusion DocIO product a go but I haven't tried it myself.

As an aside, I've had fault resolution and version backward compatibility issues with Syncfusion controls, but none of that with the XlsIO product.

Mr_SyncFuscion
06/13/2007 01:46 AM by
Mr_SyncFuscion

I've had really good luck creating Excel files with SyncFunsion. Rock solid component, clear API.

Nathan
06/13/2007 02:05 AM by
Nathan

My advice - don't use OpenXML; support for the older binary formats is far more prevalent.

I have used GemBox spreadsheet with success. It was nice and easy to implement, and relatively cheap.

goodwill
06/13/2007 02:29 AM by
goodwill

Nathan,

I agree with you, but the so called XLS format is a very tricky format. In many cases a lot of report generators would generate files that are not actually a BIFF but try to fault excel by the extension. And to the great compatibility evil of MS, Excel does handle all these files relatively correct. Now the problem is for most 3rd party we are doing some sort of reverse engineering for the file, which means its nearly impossible to make sure we have a peaceful handling of the file. My experience on using Koogra to read BIFF excel for example, does still have some hiccups when I try to open the file. So, while you are correct on the market side of binary format, it is actually not that an evil decision on choosing OpenXML too, if you intend to really have a supported native generation on the server.

Ayende,

I think it largely depends on what is your client group going to be, if its a closed workgroup (i.e. within a company), I would definitely try my best to drive everyone on OpenXML, especially MS does provides a great way to handle OpenXML on the older versions of Office (I remember its down to 2000). However if you are aiming for public audience, your situation is going to be way more complicated.

goodwill
06/13/2007 02:29 AM by
goodwill

Nathan,

I agree with you, but the so called XLS format is a very tricky format. In many cases a lot of report generators would generate files that are not actually a BIFF but try to fault excel by the extension. And to the great compatibility evil of MS, Excel does handle all these files relatively correct. Now the problem is for most 3rd party we are doing some sort of reverse engineering for the file, which means its nearly impossible to make sure we have a peaceful handling of the file. My experience on using Koogra to read BIFF excel for example, does still have some hiccups when I try to open the file. So, while you are correct on the market side of binary format, it is actually not that an evil decision on choosing OpenXML too, if you intend to really have a supported native generation on the server.

Ayende,

I think it largely depends on what is your client group going to be, if its a closed workgroup (i.e. within a company), I would definitely try my best to drive everyone on OpenXML, especially MS does provides a great way to handle OpenXML on the older versions of Office (I remember its down to 2000). However if you are aiming for public audience, your situation is going to be way more complicated.

Ron
06/13/2007 02:41 AM by
Ron

I've been using this free Excel library for the past couple years:

http://www.carlosag.net/Tools/ExcelXmlWriter/Default.aspx

You can give it an Excel XML document and it will automatically translate it to C#.

Bill Poole
06/13/2007 03:49 AM by
Bill Poole

My client requires a WYSIWYG tool to create/maintain their own templates. The solution we arrived at was to create a service that accepted a number of standard XML-based messages (e.g. Policy, Claim, etc). The service reads the template ID from the message and hands the message payload to Business Objects XI, which uses the XML as a data source to generate the output document. The service drops the document into a document management system, where it can then be retrieved/edited by the user that requested the document's creation.

This approach allows our client to create as many templates as they like against any one of the standard XML schemas, and also allows them to update their templates without any support from IT.

Business Objects XI supports Word 2003 as an output format, as well as PDF and many others.

Aaron
06/13/2007 04:22 AM by
Aaron

Seriously, how many people have OpenXML capable versions of Office? I think very few do. Especially outside the US.

Merill Fernando
06/13/2007 04:49 AM by
Merill Fernando

I second Aspose (http://www.aspose.com), we've used their PowerPoint component which is super fast gives an identical API to that of the Office Object Library.

Gian Maria Ricci
06/13/2007 05:55 AM by
Gian Maria Ricci

I used office COM automation for a long time for little document, but when documents are big or they must be generated on a web server is not a feasible solution. For simple Doc file I build some years ago a very little RTF generator, rtf format is textual and not too complex to use.

For exel file I resorted to get data from sql with the For XML instruction and then I build some XSLT that will transform the file in xml format for excel 2000.

If you do not mind to force the user to download the compatibility pack I vote for OpenXml.

Alk.

Darius Damalakas
06/13/2007 06:00 AM by
Darius Damalakas

We use OpenDocument generation via libraries provided at: http://www.opendocument4all.com/

Libraries are not good, but we do all documents currently.

Good points:

: it's open source and free,

: It's OpenDocument

: you can save the result at the moment in pdf, html and odt files

: use Boo as a scripting language inside the documents (instead of writing many replace statements)

Bad points:

: Its OpenDocument

: Library is not working always correctly

: It's not what you need (excel and word)

Stephane Tombeur
06/13/2007 06:46 AM by
Stephane Tombeur

We create word and excel 2003 documents and save them as office xml format. In word or excel, you can map elements from an xsd very easily onto parts of the document. You can then use the office 2003 xsl inference toolkit to generate xsl from the saved office xml.

Next, we create a C# class with xsd.exe from the xsd and use serialization and xslt to create office documents.

All free except the office 2003 license needed to create the 'template' document. Business users can maintain the templates from within office 2003. As long as the xsd doesn't change, there is no need for development.

Hans
06/13/2007 11:35 AM by
Hans

We've been using ExcelWriter from Softartisans for years now, even integrated VSTO solutions.They also have WordWriter.

http://www.softartisans.com/

Aaron Erickson
06/13/2007 04:04 PM by
Aaron Erickson

+1 on ExcelWriter from Softartisans. Expensive, but pretty well tested, and a reasonable API. Great for running behind a server - optimized for exactly that purpose. I used it with great success for an application that had to generate word, on the fly, from behind a employee opinion survey web app that needed to be able to serve thousands of users per hour.

Jay R. Wren
06/13/2007 06:14 PM by
Jay R. Wren

I don't know about Word, but

+1 for http://www.carlosag.net/Tools/ExcelXmlWriter/Default.aspx

It was mentioned in Windows Developer Powertools book and i was happy to find it.

Adi
06/13/2007 10:23 PM by
Adi

I collected a list from the recommendations here so far:

http://dotmad.blogspot.com/2007/06/creating-ms-office-documents-from-code.html

Shawn Wheatley
06/14/2007 03:17 AM by
Shawn Wheatley

Because my current customer is pretty conservative about deploying any new software (probably including the openxml package for office 2003) we went the custom XML/XSLT route. As you always do Ayende, please post what you end up using and why. I've already found some good stuff in the comments here ;)

Bob Banks
06/14/2007 12:50 PM by
Bob Banks

I second CarlosAg's Excel XML Writer.

http://www.carlosag.net/Tools/ExcelXmlWriter/Default.aspx

Pedro Teixeira
06/14/2007 02:27 PM by
Pedro Teixeira

I need to make the same decision in the next days, and started to evaluate:

http://www.activexls.com/

It costs less than $300 (much cheaper than aspose), and it seems sufficient to get the job done.

Hans
06/14/2007 05:26 PM by
Hans

Just received the news that MS has acquired OfficeWriter from Softartisans...

Comments have been closed on this topic.