Is there any easy to implement library that can be used to read excel files and may be create them later on? is this my best bet?
-
2possible duplicate of [Create Excel (.XLS and .XLSX) file from C#](http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c) – Neil Knight Jan 17 '11 at 20:42
-
Yes, if you want full ability to read and edit a Excel file, the Automation Interface is likely your best bet. Depending on what you want to do, sometimes a simple CSV file can use. Excel will suck these up easily. But that would be used to create an Excel file . . . the problem you stated was to read a Excel file . . . the Automation interface . . . complex to learn and use (in its fullness), but you can do EVERYTHING to the sheet you can do by hand. – Frank Merrow Jan 17 '11 at 20:43
-
Are you creating a WinForm to do this or some other type of application? – NDraskovic Mar 16 '13 at 18:56
11 Answers
Try this: http://epplus.codeplex.com
EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx).

- 13,678
- 8
- 61
- 92
If you are willing to commit yourself to a later version of Excel (2007+) you can also take a look at the OpenXML SDK. It's free, doesn't tie you to having MS Office installed on the machine it will be running on and there are quite a few resources available on how to use it online (including blogs from the OpenXML team).
There is excel package plus:
Only works on xlsx though, but Office 2003 is cycling out anyway.

- 78,642
- 66
- 377
- 442
You can use ExcelLibrary ,Although it works for .xls only which is 2003 format
The aim of this project is provide a native .NET solution to create, read and modify Excel files without using COM interop or OLEDB connection.
I had a chance of using EPPLUS ,it was wonderful :) ,It works for new excel format .xlsx which is used in 2007/2010
EPPlus is a .net library , you can read and write to excel files ,create charts ,pictures ,shapes... and Much more
Also take a look at this SO post

- 1
- 1

- 4,294
- 5
- 38
- 61
I've used oledb, interop and just started using Epplus. So far epplus is proving to be simplest. http://epplus.codeplex.com/
However, I just posted a problem I have with epplus, but I posted some code you could use as reference.
I like to use ExcelDataReader for reading and the aforementioned EPPlus for writing. Here's an example.
Here's an example of reading with it:
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
// Reading from a binary Excel file ('97-2003 format; *.xls)
// IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
// Reading from a OpenXml Excel file (2007 format; *.xlsx)
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
// DataSet - The result of each spreadsheet will be created in the result.Tables
DataSet result = excelReader.AsDataSet();
// Free resources (IExcelDataReader is IDisposable)
excelReader.Close();
var cdm = new ValueSetRepository();
for (int i = 0; i < result.Tables.Count; i++)
{
// CHECK if tableNames filtering is specified
if (tableNames != null)
{
// CHECK if a table matches the specified tablenames
var tablename = result.Tables[i].TableName;
if (!tableNames.Contains(tablename))
{
continue;
}
}
var lookup = new ValueSetLookup();
lookup.CmsId = result.Tables[i].Rows[2][0].ToString();
lookup.NqfNumber = result.Tables[i].Rows[2][1].ToString();
lookup.Data = new List<ValueSetAttribute>();
int row_no = 2;
while (row_no < result.Tables[i].Rows.Count) // i is the index of table
// (sheet name) which you want to convert to csv
{
var currRow = result.Tables[i].Rows[row_no];
var valueSetAttribute = new ValueSetAttribute()
{
Id = currRow[0].ToString(),
Number = currRow[1].ToString(),
tName = currRow[2].ToString(),
Code = currRow[7].ToString(),
Description = currRow[8].ToString(),
};
lookup.Data.Add(valueSetAttribute);
row_no++;
}
cdm.AddRecord(lookup);

- 2,662
- 1
- 26
- 50
A company I used to work for did a lot of research on this and decided a product by SoftArtisans was their best bet: OfficeWriter
I always found it strange how weak the support for Excel reading and writing was. I'm pretty sure that if you use Microsoft's libraries you have to have Excel installed anyway which is an extra expense just like OfficeWriter.

- 6,080
- 4
- 42
- 59
You could either go for VBA or use the free library from FileHelpers. If you are planning to buy some commerical solutions, I would recommend ASPOSE

- 3,425
- 7
- 30
- 39
According to this website you need to include a reference to the Microsoft Excel 12.0 Object library. From there, you need to do a few things to open up the file. There's a code sample on the website.
PS - Sorry it's not too detailed but I couldn't find the Microsoft Office developer reference with more details.

- 3,529
- 4
- 26
- 29
I used ExcelLibrary with very great results! (until now it support Excel 2003 or lower versions).

- 2,080
- 12
- 22
-
Excel library has a bug, one cannot open files generated with it in Excel 2010 (at least not if < 100 columns&rows). – Stefan Steiger Jan 18 '11 at 12:47
-
Really? Actually i've managed file with max 70-80 rows and this problem never occur! Thanks for letting me informed! – Roberto Conte Rosito Jan 18 '11 at 13:52
-
Correction: The magic number is 50, but it seems to be somewhat arbitrary in general, I think the proper definition is if the generated file stream is shorter than 4096 bytes. And only in Excel 2010, in all other versions, it works fine. – Stefan Steiger Oct 30 '12 at 08:23
Yes, multiple open-source libraries exist to help read and/or write Excel spreadsheets using C#.
Here is a shortlist of C# libraries:
An up-to-date curated list is maintained here.
Example: Reading Excel File using ExcelMapper
a. Install using NuGet, by running below command in NuGet Packet Manager:
Install-Package ExcelMapper
b. Sample C# Code for ExcelMapper
public void ReadExcelUsingExcelMapperExtension()
{
string filePath = @"C:\Temp\ListOfPeople.xlsx";
var people = new ExcelMapper(filePath).Fetch<Person>().ToList();
}
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
Disclaimer: I like the conciseness of ExcelMapper, therefore included sample code for this package. To do the same using other libraries, requires a lot more code.

- 2,175
- 20
- 23