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...)

Wim ten Brink
  • 25,901
  • 20
  • 83
  • 149
  • Can't you just do this with COM? Just wondering. – jgallant Jun 08 '09 at 12:58
  • Well, the code is part of a web server and there's no Office installed on this web server, nor will they ever install Office or Excel on this web service. Btw, using XSLT works just fine and creates the result I want. But since I'm the only XSLT expert at my company, I'd like to provide a solution that other team members can understand. – Wim ten Brink Jun 08 '09 at 13:18

3 Answers3

1

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/

1

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
  • 5,150
  • 2
  • 33
  • 41
  • 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. – Wim ten Brink Jun 08 '09 at 14:08
0

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

Arnkrishn
  • 29,828
  • 40
  • 114
  • 128
  • 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. – Wim ten Brink Jun 08 '09 at 13:23