Simplexcel 2.0.5

It’s been a few month since I released Simplexcel 2.0.0, which was a major change in that it added .net Standard support, and can be used on .net Core, incl. ASP.net Core.

Since then, there have been a few further feature updates:

  • Add Worksheet.Populate<T> method to fill a sheet with data. Caveats: Does not loot at inherited members, doesn’t look at complex types.
  • Also add static Worksheet.FromData<T> method to create and populate the sheet in one.
  • Support for freezing panes. Right now, this is being kept simple: call either Worksheet.FreezeTopRow or Worksheet.FreezeLeftColumn to freeze either the first row (1) or the leftmost column (A).
  • If a Stream is not seekable (e.g., HttpContext.Response.OutputStream), Simplexcel automatically creates a temporary MemoryStream as an intermediate.
  • Add Cell.FromObject to make Cell creation easier by guessing the correct type
  • Support DateTime cells
  • Add support for manual page breaks. Call Worksheet.InsertManualPageBreakAfterRow or Worksheet.InsertManualPageBreakAfterColumn with either the zero-based index of the row/column after which to create the break, or with a cell address (e.g., B5) to create the break below or to the left of that cell.

Simplexcel is available on Nuget, and the source is on GitHub.

Simplexcel 2.0.0

A couple of years ago, I created a simple .net Library to create Excel .xlsx sheets without the need to do any COM Interop or similar nonsense, so that it can be used on a web server.

I just pushed a major new version, Simplexcel 2.0.0 to NuGet. This is now targeting both .net Framework 4.5+ and .NET Standard 1.3+, which means it can now also be used in Cross-Platform applications, or ASP.net Core.

There are a few breaking changes, most notably the new Simplexcel.Color struct that is used instead of System.Drawing.Color and the change of CompressionLevel from an enum to a bool, but in general, this should be a very simple upgrade. Unless you still need to target .net Framework 4 instead of 4.5+, stay on Version 1.0.5 for that.

Simplexcel 1.0.3

A while ago I created my own, simple Excel .xlsx creation library for .net 4.0+. The reason I did this was because I was unhappy with the ones on the market – many of them tried to replicate every feature Excel has to offer but don’t test actually against the actual Excel application and thus miss things like sheet lengths/invalid characters (which are NOT part of the OpenXML Spreadsheet standard) or allow to otherwise create invalid Excel files, prompting Excel to give you a super useless “Invalid data found, do you want to recover?”.

Simplexcel is my attempt at a library that may not offer all the features Excel can do, but tries to make sure that every feature actually works with every applicable version of Excel (2007, 2008 for Mac, 2010, 2011 for Mac and 2013).

Today I updated it:

Version 1.0.3 (2013-08-20)

  • Added support for external hyperlinks
  • Made Workbooks serializable using the .net DataContractSerializer

Full Documentation: http://mstum.github.io/Simplexcel/
Nuget.org Package Page: http://www.nuget.org/packages/simplexcel/
GitHub Page: https://github.com/mstum/Simplexcel

Simplexcel – simple .xlsx library for .net

As part of almost every application I work on, I need to create Excel sheets one way or the other, usually from an ASP.net MVC application. During the years, I’ve tried several approaches, and they all sucked one way or the other:

  • COM Interop: By far the worst option. Requires an installed Excel. Slow. Error prone. Resource-intensive. Not supported in a server environment.
  • CSV or HTML Tables: Only supports a single worksheet, not much formatting, prone to break Excel’s heuristics (e.g., the string “00123” is interpreted as a number, stripping the leading zeroes. For big numbers, Excel loves to use scientific notation, which sucks for Barcodes which should just be interpreted as strings) and hard to create (CSV is a pain if you need to escape quotes or have newlines)
  • Excel 2003 XML/SpreadsheetML: A crutch. Uncertain future, limited options, big files. But actually, not too bad.
  • One of the many Excel 2007+ .xlsx libraries: I tried about 4 or 5, and they all sucked in a different way. No offense, but some library authors try to cover the entirety of Excel’s capabilities, leading to an awkward API. Many don’t catch specific Excel limitations that aren’t part of the standard (e.g., Sheet name length or invalid characters), which means I’m creating sheets that cause Excel to tell me there was invalid data, leaving me puzzled how to fix that.
  • Going Low-Level with the OpenXML SDK 2.0. Believe me, you don’t want to go down that road. There is very little help creating the documents, and if you want certain features that seem obvious (e.g., setting the Author of a document, which requires adding the creator element to core.xml) you will find that there is actually no way to do it.

So, all solutions I tried sucked. Which means that I set out to create another solution that sucks slightly less. Armed with some spare time, the ECMA-376 standard and Excel 2007 and 2010 to actually test against, I created a library that has a limited set of features, but implements them well, handles errors properly and (hopefully) has a good API for you guys to work against.

Features

  • You can store numbers as numbers, so no more unwanted conversion to scientific notation on large numbers!
  • You can store text that looks like a number as text, so no more truncation of leading zeroes because Excel thinks it’s a number
  • You can have multiple Worksheets
  • You have basic formatting: Font Name/Size, Bold/Underline/Italic, Color, Border around a cell
  • You can specify the size of cells
  • Workbooks can be saved compressed or uncompressed (CPU Usage vs. Network Traffic)
  • You can specify repeating rows and columns (from the top and left respectively), useful when printing.
  • Fully supported in ASP.net and Windows Services (The documentation contains an example ActionResult for ASP.net MVC)

Usage

You can get the Simplexcel Nuget Package for .net 4.0 Client Profile or higher – https://nuget.org/packages/simplexcel

Documentation can be found at http://mstum.github.com/Simplexcel/

Source Code

Licensed under the MIT License, the code can be found at https://github.com/mstum/Simplexcel