Reputation: 15207
I am using excel Library to open a spread Sheet and read its contents, I am using this library over the interop library as the interop library causes issues on the server machine i hope to host on.
https://code.google.com/p/excellibrary/
using ExcelLibrary.SpreadSheet;
Stream fileStream = System.IO.File.OpenRead(excelFileName); //FilePath
Workbook book = Workbook.Load(fileStream); //Exception thrown
Worksheet sheet = book.Worksheets[0];
When running the code, you can see the file stream load:
When i step to next line i get the exception. Buffer cannot be null.
After the exception the stream reader becomes canRead false:
Upvotes: 1
Views: 3656
Reputation: 12607
As @pomster pointed out, the problem most times here is:
The XLS file being of type "5.0/95" instead of "97-2003"
Upvotes: 3
Reputation: 1
You need the @
symbol at the front of your path filename.
Try
excelFileName = string.Format(@"{0}",excelFileName);
Upvotes: -1
Reputation: 91
VB.NET Code:
Public Function importSheet(fileName As String) As Boolean
Dim fileStream = System.IO.File.OpenRead(fileName)
Dim book = ExcelLibrary.SpreadSheet.Workbook.Load(fileStream)
Dim sheet = book.Worksheets(0)
'TO DO
Return True
End Function
Look for folder's permission.
When System.IO library has many Exceptions, look read/write folder's and files permission.
Upvotes: 1
Reputation: 560
I just created a simple program and I dont get this Exception,
Can you check you Excel file ? may be it is corrupt.
you can make a simple program that is just opening this application ?
string excelFileName = "";
excelFileName = @"E:\Innovation\PAKISTAN.xls";
Stream fileStream = System.IO.File.OpenRead(excelFileName); //FilePath
Workbook book = Workbook.Load(fileStream); //Exception thrown
Worksheet sheet = book.Worksheets[0];
Upvotes: 0
Reputation: 22008
You have to specify file name, not stream to method Workbook.Load
, see example in own link:
string file = "C:\\newdoc.xls";
// open xls file
Workbook book = Workbook.Load(file);
Worksheet sheet = book.Worksheets[0];
If there is an overload for it, then you have to ask library author for assistance (it looks like a bug).
Upvotes: 0