[c#] .NET Excel Library that can read/write .xls files

I'm looking for an Excel library which reads/writes .xls (not .xlsx) files.

I'm using excellibrary but it's very buggy and I can't seem to open the files I create. The issue has been known for almost a year and hasn't been fixed yet.

I've seen in another thread someone suggested EPPlus, but that only works with the 2007/2010 .xlsx format.

I've used Koogra in the past, and been quite happy with it, but I believe it can only read... not write.

If you know of a library, please let me know what it's called.

Edit: I'm quite happy to create my Excel file with the built-in Microsoft.Office.Interop.Excel if necessary, however my machine has Office 2007 and the target machines only have Office 2003. I noticed I have 2 file versions for that library: 12, and 14. I checked the Excel version on the target machines and it's 11.8169.8172 - I'm assuming that the built-in Excel interop will not work on the target?

This question is related to c# excel xls read-write

The answer is


I'd recommend NPOI. NPOI is FREE and works exclusively with .XLS files. It has helped me a lot.

Detail: you don't need to have Microsoft Office installed on your machine to work with .XLS files if you use NPOI.

Check these blog posts:

Creating Excel spreadsheets .XLS and .XLSX in C#

NPOI with Excel Table and dynamic Chart

[UPDATE]

NPOI 2.0 added support for XLSX and DOCX.

You can read more about it here:

NPOI 2.0 series of posts scheduled


You may consider 3rd party tool that called Excel Jetcell .NET component for read/write excel files:

C# sample

// Create New Excel Workbook
ExcelWorkbook Wbook = new ExcelWorkbook();
ExcelCellCollection Cells = Wbook.Worksheets.Add("Sheet1").Cells;

Cells["A1"].Value = "Excel writer example (C#)";
Cells["A1"].Style.Font.Bold = true;
Cells["B1"].Value = "=550 + 5";

// Write Excel XLS file
Wbook.WriteXLS("excel_net.xls");

VB.NET sample

' Create New Excel Workbook
Dim Wbook As ExcelWorkbook = New ExcelWorkbook()
Dim Cells As ExcelCellCollection = Wbook.Worksheets.Add("Sheet1").Cells

Cells("A1").Value = "Excel writer example (C#)"
Cells("A1").Style.Font.Bold = True
Cells("B1").Value = "=550 + 5"

' Write Excel XLS file
Wbook.WriteXLS("excel_net.xls")

Is there a reason why you can't use the Excel ODBC connection to read and write to Excel? For example, I've used the following code to read from an Excel file row by row like a database:

private DataTable LoadExcelData(string fileName)
{
  string Connection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=1\";";

  OleDbConnection con = new OleDbConnection(Connection);

  OleDbCommand command = new OleDbCommand();

  DataTable dt = new DataTable(); OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$] WHERE LastName <> '' ORDER BY LastName, FirstName", con);

  myCommand.Fill(dt);

  Console.WriteLine(dt.Rows.Count);

  return dt;
}

You can write to the Excel "database" the same way. As you can see, you can select the version number to use so that you can downgrade Excel versions for the machine with Excel 2003. Actually, the same is true for using the Interop. You can use the lower version and it should work with Excel 2003 even though you only have the higher version on your development PC.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to excel

Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support Converting unix time into date-time via excel How to increment a letter N times per iteration and store in an array? 'Microsoft.ACE.OLEDB.16.0' provider is not registered on the local machine. (System.Data) How to import an Excel file into SQL Server? Copy filtered data to another sheet using VBA Better way to find last used row Could pandas use column as index? Check if a value is in an array or not with Excel VBA How to sort dates from Oldest to Newest in Excel?

Examples related to xls

Export to xls using angularjs How can I quickly and easily convert spreadsheet data to JSON? count files in specific folder and display the number into 1 cel xls to csv converter How to parse Excel (XLS) file in Javascript/HTML5 Converting JSON to XLS/CSV in Java Importing Excel files into R, xlsx or xls .NET Excel Library that can read/write .xls files Reading/parsing Excel (xls) files with Python How to change pivot table data source in Excel?

Examples related to read-write

Open files in 'rt' and 'wt' modes How to read/write arbitrary bits in C/C++ .NET Excel Library that can read/write .xls files Reading/Writing a MS Word file in PHP