Home » Programming » C# » Create an Excel file in C# without Microsoft Office or Third party plugins

Create an Excel file in C# without Microsoft Office or Third party plugins

posted in: ASP.NET, C#, Programming, VB.Net, XML 0

What I’m about to say seems paradoxical, but the reality is that in open environments (as in PHP for example) it is often easier and we have less problems in creating or converting files in proprietary systems, compared to what happens on frameworks such as Microsoft’s .Net; this is the case when we have to create an Excel file (XLS / XLSX) in C# without having a copy of Microsoft Office on the server, or other third party plugins installed, without the right libraries in our project we will have several headaches. A quick solution is to use the open-source library ExcelLibrary. This looks to be a port of the PHP ExcelWriter, it’s very simple, small and easy to use.

Using ExcelLibrary

Workbook workbook = new Workbook();
Sheet sheet = workbook.Sheet("Sheet1");
Row row = sheet.Row(2);
Cell cell = row.Cell(3);
string text = cell.Value;

Main features

  • No dependencies except .NET Framework 4.5. Easy to include in other solutions.
  • Built and extendable with LINQ. Most collections in the library (e.g. Workbook.Sheets or Row.Cells) is of type IEnumerable<T>, which allows you to use LINQ queries to find exactly what you need.
  • Respects the visibility of sheets, rows and columns. Set the IncludeHidden option to trueto return hidden objects.
  • Well-tested. The library is being developed using principles of Test-driven development (TDD). A large set of unit tests verifies that new bugs are not introduced on code changes.
  • Well-documented. A software library is only as useful as its documentation.

Another valid alternative is EPPLUS5 however it has a new license model from version 5, it’s still free to use in some cases, but will require a commercial license to be used in a commercial business.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.