You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there. I have been debugging an issue with some excel sheet throwing an error when enumerating its rows. The error message says: Sheet "Sheet1" has no heading. However, the sheet in question does have a heading. Fast forward, I found the root cause of the issue and as you can see with the code below:
privatestaticvoidMain(string[]args){// NOTE: sheet.ReadRows uses yields to return the rows and at this point the ExcelDataReader has already been closed// because of the use of `using` to open the ExcelImportervarrows=ReadSheet();Console.WriteLine(rows.Count());}privatestaticIEnumerable<ExcelPolicyDetailsImportRow>ReadSheet(){using(varstream=File.OpenRead("testing_sheet.xlsx")){using(varimporter=newExcelImporter(stream)){importer.Configuration.RegisterClassMap<PolicyDetailsImportMap>();varsheet=importer.ReadSheet();returnsheet.ReadRows<ExcelPolicyDetailsImportRow>();}}}
The rows are being read after the ExcelImporter has already been closed/disposed. My suggestion is that since ExcelDataReader has property IsClosed to tell whether the reader has been disposed of, that can be used to determine which message to show in situations where ExcelDataReader.Read() returns false.
The text was updated successfully, but these errors were encountered:
Hi there. I have been debugging an issue with some excel sheet throwing an error when enumerating its rows. The error message says: Sheet "Sheet1" has no heading. However, the sheet in question does have a heading. Fast forward, I found the root cause of the issue and as you can see with the code below:
The rows are being read after the ExcelImporter has already been closed/disposed. My suggestion is that since
ExcelDataReader
has propertyIsClosed
to tell whether the reader has been disposed of, that can be used to determine which message to show in situations whereExcelDataReader.Read()
returns false.The text was updated successfully, but these errors were encountered: