Monday, January 08, 2007

ExcelPackage Project - An Open XML Excel Wrapper API

Open-source API for SpreadsheetML documents

More people are starting to build and share open-source APIs around Open XML development.  ...

For .NET developers, the System.IO.Packaging API handles the low-level heavy lifting chores of Open XML development: dealing with OPC packages, relationships, and content types. But once you have those details under control, you're going to have to write a lot of XML markup to create a useful document...

...

A great example is the new ExcelPackage project on Codeplex. It was created by Dr. John Tunnicliffe, and he wrote a nice article about it for the OpenXmlDeveloper web site: "Using the Packaging API and Office Open XML to create Excel 2007 files on the server."

John's approach mimics some of the syntax and concepts that have been used in the Excel object model to allow for simple document creation.

...

using OfficeOpenXml; // namespace for the ExcelPackage assembly

FileInfo newFile = new FileInfo(@"C:\mynewfile.xlsx");
using (ExcelPackage xlPackage = new ExcelPackage(newFile)) { … }
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("My Worksheet");
worksheet.Cell(1, 1).Value = "My Data #1";
worksheet.Cell(1, 2).Value = "My Data #2";

...

Pretty cool. The ExcelPackage class makes it possible to "think like a spreadsheet" when creating the document, focusing on which cells contain which values, and hiding all the messy details of the underlying XML that is being generated...

That looks pretty cool.

When/if I need to generate XLSx's I want to remember to check this out... One issue I see is that it's licensed under GPL, so using it at work looks problematic.

Still it looks like an interesting project, one that I'll be keeping an eye on.

5 comments:

sandy.ph said...

Hi Greg,
I just know about this component today haha (chuckles), but if i want to use it as CLR in SQL Server 2008, can it? or Did you have experiences in making CLR using Office Library?

Thanks
Sandy

Greg said...

I've not done SQL CLR/Office work myself (yet... sigh)

In theory, this project may work. The trust model might be an issue though.

One thing to watch is the license on this project. It's GPL, so make sure that doesn't impact you and your project.

What also you might want to check out is the OpenXML SDK and OpenXML Power Tools,
http://coolthingoftheday.blogspot.com/search/label/OpenXML

Greg said...

Here's another OpenXML article that might help;
Generating Microsoft Office Documents with the Open XML SDK

Unknown said...

Here is my situation. For several years we have delivered excel report by transforming XML into SpreadsheetML by means of xsl stylesheets and then streaming the spreadsheetML to the browser. With the recent move to extension hardening we are encountering problems and want to use the OfficeOpenXML ExcelPackage and first load the spreadsheetML into an ExcelPackage and then stream the package to the browser. We are attempting to do this by loading the excelpackage.Workbook.WorkbookXml.LoadXml(), and also then getting a collection of Worksheet nodes from the SpreadsheetML document and loading each of them into the Workbook.WorksheetsWorksheetXml.LoadXml().

If you inspect the package after doing this you can see the xml data but then when you attempt a package.GetAsByteArray() so that you can stream it to the browser, you come up with nothing.

Please advise.

Thanks,

Steve Satterfield

Greg said...

@Steve: If you haven't tried already, the best place to probably get support for the ExcelPackage project is via its Discussions area, http://excelpackage.codeplex.com/discussions. The Project's discussions seem pretty active...