-1
我正在使用exceldatareader從excel文件讀取數據並獲取未設置爲對象實例的異常對象引用。exceldatareader c#對象引用未設置爲對象的實例
string excelpath = @"C:\Temp\Test.xls";
FileStream stream = File.Open(excelpath, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
DataTable myDataTable = result.Tables["sheet1"]; //exception "result.Tables = 'result.Tables' threw an exception of type 'System.NullReferenceException'"
檢查是否(result!= null)在訪問result.Tables [「sheet1」] –