Neither stream 'Workbook' nor 'Book' was found in file

Oct 10, 2013 at 1:24 PM
I'm getting this error trying to open some xls files using the Excel.ExcelReaderFactory

Error: Neither stream 'Workbook' nor 'Book' was found in file

Some work 100%, but others give this exception. Does anyone have any ideas?

After doing a compare between the files that work and the ones that don't I came across this right at the bottom of the ones that don't work:

Crystal Decisions Powered by Crystal

Have a look at http://stackoverflow.com/questions/19295515/excel-excelreaderfactory-cannot-open-some-files for the same question on Stack Overflow
Oct 28, 2013 at 4:40 PM
Same problem, same exception with crystal report xls file.
This because 'Excel Data Reader' defines block strings as "Workbook" and "Book", instead Crystal Report as "WORKBOOK": you have to do a case insensitive comparison!

open "Excel\Core\BinaryFormat\XlsRootDirectory.cs" and replace line 75
if (e.EntryName == EntryName)
with
if (string.Equals(e.EntryName, EntryName, StringComparison.CurrentCultureIgnoreCase))
for me it solved.

have a nice day,
marco
Nov 1, 2013 at 5:01 AM
Thanks - solved my problem after changing the ReadOption to loose

See http://stackoverflow.com/questions/19295515/excel-excelreaderfactory-cannot-open-some-files for a few more details

Pete
Dec 30, 2013 at 8:36 AM
Hi,

I am having the same problem, runs OK with xlsx, fails occasionally with xls , but I could not solve it with either solution:
  1. (mmleoni): Did not make a difference
  2. (petemunnings): The ExcelReaderFactory.CreateBinaryReader(stream, ReadOption.Loose);
    does not accept any second parameter (ReadOption or other).
    How did you get it to accept the new parameter?
Any idea?
Thanks.
Jan 2, 2014 at 11:54 AM
Edited Jan 2, 2014 at 11:54 AM
Its an overload on that Method. Do you have the latest version?
public static IExcelDataReader CreateBinaryReader(Stream fileStream)
{
  IExcelDataReader excelDataReader = (IExcelDataReader) new ExcelBinaryReader();
  excelDataReader.Initialize(fileStream);
  return excelDataReader;
}

public static IExcelDataReader CreateBinaryReader(Stream fileStream, ReadOption option)
{
  IExcelDataReader excelDataReader = (IExcelDataReader) new ExcelBinaryReader(option);
  excelDataReader.Initialize(fileStream);
  return excelDataReader;
}
Jan 2, 2014 at 12:48 PM
Hi,
Thanks petemunnings.
Yes, I understand it is an overload on the CreateBinaryReader method, but I do not seem to have that overload.
I downloaded the (said-to-be) latest version from the Download, which is 2.1 dated January 2013.
Is there a newer version I can download that has that overload, or is there a workaround to the ReadOption.Lose ?
(My original problem was errors opening the xls binaries)

samtal
Jan 2, 2014 at 1:12 PM
You can download the source code and create the overload yourself. I think that's what I did
Jan 26, 2014 at 6:28 PM
You're kidding. Why isn't the ReadOption included in the latest version?

@ petemunnings: the above Method does not work. I get compile error:
   The type or namespace name 'ReadOption' could not be found (are you missing a using directive or an assembly reference?)
Developer
Jan 27, 2014 at 9:16 AM
ReadOption is an enum at the end of ExcelBinaryReader.cs . It should be in the latest source from the repository.
Jan 28, 2014 at 1:24 AM
Ian, thank you for your reply. I downloaded the latest source code and, unfortunately, ReadOption.Loose did not fix the problem. I'm still getting "Neither stream 'Workbook' nor 'Book' was found in file".

The fix from mmleoni, however, solved the problem.
Developer
Jan 29, 2014 at 2:16 PM
Thanks. I'll add that code into the library