Is there implementation for Read by StreamReader like CsvReader?
Closed this issue · 2 comments
sagarkul commented
I want to read the file from blob storage.
So all I have is MemoryStream Object.
Currently, I am able to read it using below code with CsvReader:
`
private void ReadFile()
{
blobStream.Position = 0;
using (ICsvReader csvReader = new CsvReader(new StreamReader(blobStream)))
{
csvReader.Configuration.HasHeaderRecord = true;
/// https://github.com/JoshClose/CsvHelper/issues/523
/// https://stackoverflow.com/questions/39641220/how-to-read-a-header-from-a-specific-line-with-csvhelper
/// Skip ablow rows to get header row. This logic need to be optimize
try
{
csvReader.Read();
var fileData = csvReader.GetRecords<dynamic>().ToArray();
FileData = fileData;
}
catch (Exception readerException)
{
throw new Exception($"InvalidFileException: Unable to read the file.", readerException);
}
}
}
`
Is there a similar implementation for ExcelParser?
meghuizen commented
It's a bit late, but this is possible when reading from a Stream:
using (var workbook = new XLWorkbook(myStream, XLEventTracking.Disabled))
{
using (var csvReader = new CsvReader(new ExcelParser(workbook, config)))
{
}
}
christophano commented
Yep, as in the example above - thanks.