Home » excel » c# – Creating an Excel SpreadsheetML in code. (Without Excel!)

c# – Creating an Excel SpreadsheetML in code. (Without Excel!)

Posted by: admin April 23, 2020 Leave a comment


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

How to&Answers:

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.


I have used this library and there is even a tool to generate the C# code that you need from an exsisting excel file.


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.