fsprojects / ExcelProvider

This library is for the .NET platform implementing a Excel type provider.
http://fsprojects.github.io/ExcelProvider/
The Unlicense
141 stars 51 forks source link

openWorkbookView not checking reader status #11

Closed glchapman closed 9 years ago

glchapman commented 9 years ago

I have just been checking out the Excel Type Provider, and my initial attempt to link to an Excel file generates a null reference error (red squiggly with "Object reference not set to..."). Looking at the type provider code, it appears that files are opened by the openWorkbookView function, which in turn relies on readers provided by the ExcelDataReaders project. These readers apparently do not throw exceptions when there is a problem reading; instead, they set IsValid to false and provide an ExceptionMessage describing the error. I believe openWorkbookView should check if the reader IsValid before proceeding, and (presumably) throw an exception with ExceptionMessage if it is not. Hopefully, this will provide somewhat more helpful information about the nature of the problem in a case like mine.

glchapman commented 9 years ago

I forgot to make clear, the code I'm getting the error on (in VS Express 2013 in case that's important) is essentially:

type MyExcel = ExcelFile< @"....\SomePath\MyExcelFile.xlsb" >

I believe the underlying error is not FileNotFound, because I get a different error in VS Express if I use a bogus filename.

JohnDoeKyrgyz commented 9 years ago

Hello @glchapman,

Thanks for digging into this and suggesting a possible improvement. I have incorporated your suggestions in this commit: https://github.com/fsprojects/ExcelProvider/commit/00ec93ee09a9b377f9ef130e4cdc13ba11e1cf7b. Take a look, and see if you think this will work for you.

One thing I did notice from your code is that you are trying to open an xlsb file. Unfortunately the ExcelDataReader does not yet support this format. This is an open issue in their project https://github.com/ExcelDataReader/ExcelDataReader/issues/26.

Thanks