ExcelMapper
ExcelMapper copied to clipboard
Queston - Reading multiple parts of excel sheet performance
Hi there,
Thanks for the library, my question is about reading multiple parts of an excel sheet
Let's say the excel sheet is made of the following parts
| Id | Price |
|---|---|
| 1 | Product1 |
| 2 | Product2 |
Then lets say you have blank line and another set of rows
| Id | Car | Color |
|---|---|---|
| 1 | Ferrari | Red |
| 2 | Ford | Blue |
| 3 | MG | Green |
Using the code below, is the file loaded once and items are extracted from different row positions? Or is the file read each time? If it's the latter, is there anyway to load the file once and then just extract from that?
var products = new ExcelMapper(@"../../../xlsx/Sheet1.xlsx")
{
HeaderRowNumber = 2,
MinRowNumber = 3,
MaxRowNumber = 4,
}.Fetch<Product>().ToList();
var products = new ExcelMapper(@"../../../xlsx/Sheet1.xlsx")
{
HeaderRowNumber = 6,
MinRowNumber = 7,
MaxRowNumber = 10,
}.Fetch<Product>().ToList();
I think you should be able to create an ExcelMapper object and then make multiple Fetch() calls like so:
var excelMapper = new ExcelMapper(@"../../../xlsx/Sheet1.xlsx")
{
HeaderRowNumber = 2,
MinRowNumber = 3,
MaxRowNumber = 4,
};
var products = excelMapper.Fetch<Product>().ToList();
excelMapper.HeaderRowNumber = 6;
excelMapper.MinRowNumber = 7;
excelMapper.MaxRowNumber = 10;
var cars = excelMapper.Fetch<Car>().ToList();
Thanks I'll give it a go