Excel…lent
Generating an Excel file from .Net should be easy right? MS have good reason to have you using their formats as the de-facto standard and make it easy, huh.
Nope. Not really.
It’s a bit trickier than you might think.
Obviously with Office XP onwards, Excel supports XML and rendering the workbook as xml is fairly trivial, but I want to support aged machines running Excel 97. This means the BIFF binary format.
Starting with MSDN you find the obvious articles on using the Office Primary Interop Assemblies to interact with the Excel object model and create a workbook that way. Other articles out on the web suggest creating your own interop assemblies… Good Plan. I wonder why MS went to all the trouble of writing the PIAs then?
The PIA approach works and the code is simple enough, but because it’s COM Interop you get objects passed back out rather than the types you want, which means you have to cast stuff to what you’re expecting. This makes the code messier to read, it’s distracting and more importantly it moves type checking from a compile time task to a runtime task making it harder to find bugs.
The big issue, though, is performance. The interop is slow. My tests tasks were to produce a roughly 100 line spreadsheet with some basic formatting of just a few cells and then write it out to disk. That shouldn’t take more than oooh, TWENTY ONE SECONDS :-O and that’s after I’ve taken out the seven seconds it takes to construct the Excel object.
There has to be a better way, or even just another way! Which, of course, there is.
There are a handful of commercial products:
Aspose.Excel;
SyncFusion’s ExcelRW;
SoftArtisan’s ExcelWriter5.
to name just the ones I shortlisted.
And they are all pretty good. There are performance differences, with Syncfusion coming in at around one second to generate the test workbook and Aspose.Excel coming in fastest at 91mS with very little variation.
But some of the programming interfaces are quirky. ExcelWriter exposes a whole load of interesting stuff when referenced, such as a load of nums all starting with __MIDL and a load of com.sun.java.collections classes that suggest it wasn’t written entirely for .Net.
Again, Aspose worked the best for me as they chose to index the sheet, row, column and cell indices from 0, yep zero, just like everything else in C#. Syncfusion, on the other hand indexed them all from 1. :-/
But I’m still looking for a good free, open-source, C# implementation to use. I found a little VB6 version, ported to VB.Net on Planet Source Code, but it isn’t very well written; it swallows exceptions and one or two other things. It also exposes the details of BIFF8 format a little too literally for my liking. Oh, and I couldn’t get it to do formatting, but that’s probably just me being dumb.
So, for the project I’m on we’ll probably buy one, but maybe I should offer some time to koogra.
Search
Right Now (ish)
- @danieljohnlewis I meant it more in a "where's my flying car" kind of a way ;-) in reply to danieljohnlewis 46 mins ago
- Why can we now do face recognition, but still not really do speech recognition (the real stuff, not just a few commands)? timeliness? 1 hr ago
- lmao: http://tinyurl.com/8elayq 1 hr ago
- More updates...
Categories
- .Net Technical
- Blog on Blog
- commands I have issued
- Enterprise Architecture
- event
- Fiction Book Review
- Food
- Interaction Design
- Internet Social Impact
- Internet Technical
- IP Law
- Library Tech
- Music
- New Toy
- Non-Fiction Book Review
- Other Technical
- Personal
- Random Thought
- Resourcing
- Security And Privacy
- Semantic Web
- Software Business
- Software Engineering
- Talis Technical
- Uncategorized
- Working at Talis
- [grid::blogpaper]
- [grid::fatherhood]
Archive
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- December 2007
- November 2007
- October 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- September 2006
- August 2006
- June 2006
- February 2006
- January 2006
- December 2005
- November 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004
- February 2004
- December 2003
- November 2003
- August 2003
- July 2003
- June 2003
- May 2003
- March 2003
- January 2003
- May 2002
- March 2002
- August 2001
- May 2001
- April 2001
- January 2001
- December 2000
- November 2000
- December 1999
- November 1999
- July 1999