0

So I am downloading some excel files from a service that calculates a day of a worker in this company when I download this file this comes up:
file

Now I think everything alright, it should work fine. So here's the deal if I try and open this file in my Visual Studio 2015 with an openfiledialog I get this error.

error

Now when I go and save the excel as 97-2003 xls file it works with createbinaryreader. And if I save it as a normal excel format xlsx file it works with createopenxmlreader.

How can I fix this so I don't need to go to the excel file and specially save it as a excel-workmap (xls or xlsx)?

PS: I am putting this excel file into a datagridview.

shA.t
  • 16,580
  • 5
  • 54
  • 111

1 Answers1

1

These notes were too mush to comment, so I let them as an answer here:

Note 1: Use ExcelReaderFactory in aproper way like this:

IExcelDataReader reader;
if (file.Extension.Equals(".xls"))
    reader = ExcelReaderFactory.CreateBinaryReader(stream);
else if (file.Extension.Equals(".xlsx"))
    reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
else
    throw new Exception("Invalid Excel File");

Note 2: Use AsDataSet() method without parameter.

result = reader.AsDataSet();

Note 3: You can use newer version of ExcelDataReader.

shA.t
  • 16,580
  • 5
  • 54
  • 111