Best way to work with XLS and XLSX files

Asked

Viewed 1,250 times

-1

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

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

Follow an example below:

Planilha Excel

Observing: Inside the XLS or XLSX file will have only one Worksheet

  • The Library I use to manipulate and create spreadsheets is the Epplus, with it you can manipulate virtually everything, that tutorial teaches you to read a spreadsheet.

  • In the current form your question is not good for the standards of website. [Ask] See: [help/dont-Ask]. I’m not saying that the question is all bad. They’ve asked something like this and it hasn’t produced very good things. http://answall.com/questions/23080/trabalhando-com-dados-do-excel-no-c

  • Thank you @Laerte for your editing activity.

  • @Toncunha, you can also use NPOI, in that link have an example with XLS files, for XLSX files just import XSSF instead of HSSF

1 answer

1

I use a Nuget package called Exceldatareader:

https://www.nuget.org/packages/ExcelDataReader/

The Github repository is 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();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.