Best way to work with XLS and XLSX files

-1

What is the best way to work with Excel spreadsheets, XLS and XLSX in C #?

I need to perform cell reads according to the column name, which is specified in the first row.

Here is an example below:

Note: Inside the XLS or XLSX file you will only have one worksheet

    
asked by anonymous 26.11.2014 / 19:54

1 answer

1

I use a NuGet package called ExcelDataReader :

  

link

The GitHub repository stays here .

An example:

var stream = File.Open(filePath, FileMode.Open, FileAccess.Read);

IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();

excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();

while (excelReader.Read())
{
    //excelReader.GetInt32(0);
}

excelReader.Close();
    
27.11.2014 / 00:54