tags:

views:

2874

answers:

5

I have a dataset that I have modified into an xml document and then used a xsl sheet to transform into an Excel xml format in order to allow the data to be opened programatically from my application. I have run into two problems with this:

  1. Excel is not the default Windows application to open Excel files, therefore when Program.Start("xmlfilename.xml") is run, IE is opened and the XML file is not very readable.

  2. If you rename the file to .xlsx, you receive a warning, "This is not an excel file, do you wish to continue". This is not ideal for customers.

Ideally, I would like Windows to open the file in Excel without modifying the default OS setting for opening Excel files. Office interop is a possibility, but seems like a little overkill for this application. Does anyone have any ideas to make this work?

The solution is in .Net/C#, but I am open to other possibilities to create a clean solution.

+1  A: 

What if you save the file as an xlsx, the extension for XML-Excel?

sgwill
Ah, thanks for reminding me. That is actually where I ran into situation #2 where the error message is displayed. I'll go edit that now...
Trevor Abell
xslx is not xml excel, it's office 2007 v. excel (rename xslx to zip and you'll see it's basically just a zip file containing everything)
Darren Kopp
+1  A: 
Process.Start(@"C:\Program Files\Microsoft Office\Officexx\excel.exe", "yourfile.xml");

That being said, you will still get the message box. I suppose that you could use the Interop, but I am not sure how well it will work for you.

MagicKat
This worked well. There is no popup, presumably because the extension is still .xml.
Trevor Abell
Glad that it worked :)
MagicKat
A: 

As Sam mentioned, the xlsx file extension is probably a good route to go. However, there is more involved than just saving the xml file as xlsx. An xlsx is actually a zip file with a bunch of xml files inside folders. I found some good sample code here which seems to give some good explanations although I haven't personally given it a try.

Bryant
A: 

Apologies in advance for plugging a third party library, and I know it's not free, but I use FlexCel Studio from TMS Software. If you're looking to do more than just dump data (formatting, dynamic cross-tabs, etc) it works very well. We generate hundreds of reports a week using it.

FlexCel accepts strongly-typed datasets, it can group data according to relationships, and the generated Excel file looks so much cleaner than what you can get from a Crystal Reports excel export. I've done the crystal reports thing, and the OLE automation thing. FlexCel is a steal at $125 EU.

ranomore
+3  A: 

If you insert the following into the 2nd line of your XML it directs Windows to open with Excel

<?mso-application progid="Excel.Sheet"?>
Jason Z