tags:

views:

992

answers:

8

Our product has the requirement of exporting its native format (essentially an XML file) to Excel for viewing/editing. However, what this entails is having a dependency on Excel (or Office) itself for our product build - something that we do not want.

What we have done is export the data from our native format to a csv file which can be opened in Excel. If user selects an option to open the generated report as well, we (try to) launch Excel application to open it (ofcourse it requires Excel to be already present on the client system).

The data for most part is flat list of records.

Is there a better format (or even a better way) to handle this requirement? This is a common requirement for many products - how do you handle this?

+1  A: 

I'm using ExcelPackage to create spreadsheets in one of my side projects. Works pretty good, but (at least the version I'm using) its a bit limited when it comes to styling and calculations.

ExcelPackage lets you create OOXML docs (.xslx files) that are natively compat with 2k7, but you can download a plugin for previous versions of Office from MS.

Will
+1  A: 

We export our data either using Excel objects (COM based code) on client side or CSV file (usually on server side, but can be used on client side too). And we allow copy data from grids in simple html format, what can be pasted into Excel without problems. For one customer we even had to export data [from sql stored procedure] into csv-like tab-separated format, but named file like xxxxx.xls - this way excel opened that file in more correct way than csv file. Ugly hack, but worked well.

CSV is most compatible format (no dependencies on external applications or libraries), but customers don't like it. Maybe we need to incorporate some XLS export code, this way all users will be happy :)

Arvo
A: 

If you are working in Java, Checkout the POI project from APACHE. http://poi.apache.org/

Simple, nice, complete, powerful.

A: 

We started with Office on the server, but that's not very nice. We had to kill processes that hung, and had quite a bit of a performance dip. We thought about putting it on a different machine, but didn't bother after trying and using Aspose (commercial). We don't have a very large number of simultaneous users, but complex documents. Simple ones can be handled easier with csv.

Stephan Eggermont
I don't think you can use any desktop office products on a server. I'm sure there's gotta be something in the licensing about that.
Will
There is Will. The license specifically prohibits you from using Excel or its libraries on servers. I ran into that problem a couple of years ago and I'd be surprised if it has changed.
DMKing
The license is not quite that strict, but you might want to get legal advice on how to handle this correctly.
Stephan Eggermont
+1  A: 

If .csv isn't formatted enough, you could create a template in Excel, and use a little bit of VBA code to import the CSV and format it appropriately. This way your app is only concerned with generating the .CSV, and will use the same .XLS for each export.

If you're careful, you should be able to get this to work with most versions of Excel seamlessly.

Tony Arkles
A: 

I've used FlexCel Studio for a couple of projects now. It's very functional and fast. 100% managed code, no dependencies. Sounds like you'd use the "Reports" feature which allows you to define an empty report template in Excel, then pass datatable and volia, it's populated with your data.

TMS Software

matt eisenberg
+2  A: 

Excel versions, both 2007 and several previous, have native XML formats. 2007, obviously, is XML by default, and earlier versions have the ability to save as XML. This SO question deals with the issue. I'd guess a little inspection would give an idea of what's required. I don't know if a XSD/DTD exists for older versions, but a little creative Googling might yield something.

Mike Woodhouse
+2  A: 

As other people pointed out, it is reasonably easy to generate Excel XML files. You can do this in multiple ways. For example:

  1. By creating a template Excel XML document, and then using XML DOM to stuff your data into the template, or
  2. Converting the template Excel XML into an XSLT, and then simply passing your proprietary XML as input to XSLT.