CsvHelper.Excel
CsvHelper.Excel copied to clipboard
Incompatable with CSVHelper v30
Describe the bug
CsvHelper.Excel v27.2.1 is incompatable with CSVHelper v30.0.0. Specifically, some of the breaking changes in that version add:
bool LeaveOpen { get; } to IWriterConfiguration and IParserConfiguration. This causes CsvHelper.Excel to throw a System.MissingMethodException when trying to open an Excel file (at least via the MemoryStream method described below).
System.MissingMethodException: Method not found: 'Boolean CsvHelper.Configuration.IParserConfiguration.get_LeaveOpen()'.
at CsvHelper.Excel.ExcelParser..ctor(Stream stream, String sheetName, CsvConfiguration configuration)
To Reproduce Steps to reproduce the behavior:
FileStreamOptions readOnly = new FileStreamOptions(){Mode = FileMode.Open, Access = FileAccess.Read, Share = FileShare.ReadWrite};
CsvConfiguration ExcelConfig = new CsvConfiguration(CultureInfo.InvariantCulture){
IgnoreBlankLines = true
,ShouldSkipRecord = args => args.Row.Parser.Record.All(string.IsNullOrWhiteSpace)
,HasHeaderRecord = true
};
MemoryStream ms = new();
using(FileStream fileStream = new FileStream("path/to/file.xlsx", readOnly)) { fileStream.CopyTo(ms); }
using(CsvReader rdr1 = new CsvReader(new ExcelParser(ms,"Sheet1",ExcelConfig))) // <- Error occurs here
using(CsvReader rdr2 = new CsvReader(new ExcelParser(ms,"Sheet2",ExcelConfig)))
{
var results1 = rdr1.GetRecords<dynamic>();
var results2 = rdr2.GetRecords<dynamic>();
}
Expected behavior Program runs without issue.
Versions (please complete the following information):
- CSVHelper: 30.0.0
- CSVHelper.Excel.Core: 27.2.1
I put in a pull request this past week for this issue since I was encountering it, also