tags:

views:

659

answers:

3

With Excel 2003 and higher it is possible to use the SpreadsheetML format to generate Excel spreadsheets with just an XML stylesheet and XML data file. I've used this in some project and works quite nice, even though it's not easy to do. From the Microsoft Download site I've downloaded the XSD's that make up SpreadsheetML and in my ignorance, I've tried to convert them to C# classes. Unfortunately, xsd.exe isn't very happy about these schema files so I tend to be stuck. I don't need an alternative solution to SpreadsheetML since it works fine for my needs. It's just that my code would be a bit easier to maintain for my team members if it's not written in a complex stylesheet. (It sucks to be the only XSLT expert in your company.)

All I want to know if someone has successfully created Excel SpreadsheetML files with .NET without the use of third-party code and without XSLT. And if you do, how did you solve this?

(Or maybe I just have to discover how to add namespaces to XML elements within XML.Linq...)

A: 

Hi

I had started on a similar problem a few weeks back, but due to some impending issues I had to put it at the back burner.

Back then I referred to this http://www.codeproject.com/KB/aspnet/ExportClassLibrary.aspx?fid=113399&df=90&mpp=25&sort=Position&tid=2609600

I really couldn't get started with it but plan to get back on it soon. I hope the link helps.

cheers

Andriyev
Unfortunately, the spreadsheet I generate is more than just a list of data converted to Excel. It contains several formula's and some formatting for the user to use immediately after downloading. It's only purpose is an easy way for users to validate the data in the server. The same data is also served through a web service to a client application. It's just that the Excel sheet is easier to validate.
Workshop Alex
+1  A: 

A while ago I used the XmlDocument and friends to create a SpreadsheetML document with formulae, formats and so on, so it is possible if a bit fiddly.

This MSDN page is what you need to get started with using the namespace in LINQ.

Ant
And that's exactly what I was looking for! :-) At least, my team members have more experience with C# than XSLT thus it doesn't matter that it becomes a bit fiddly.
Workshop Alex
Glad to be of help :)
Ant
+1  A: 

I have used this library and there is even a tool to generate the C# code that you need from an exsisting excel file. http://www.carlosag.net/Tools/ExcelXmlWriter/

Peter
Interesting, unfortunately third-party code. Still, good tip! +1
Workshop Alex