donnytian / Npoi.Mapper

Use this tool to import or export data with Excel file. The tool is a convention based mapper between strong typed object and Excel data via NPOI.
MIT License
599 stars 115 forks source link

mapper.Take read error #140

Open rickt96 opened 3 months ago

rickt96 commented 3 months ago

After a recent update of the package i'm facing issue in the import/export process.

When i try to read an imported file mapper.take() loads only 100 items (according to default maxErrorRows parameter) and all items has null values

During the export process i use an existing file as template, and i fill the rows dinamically

var tmpl = templatesDirectory.GetFiles($"products.xls").FirstOrDefault();

HSSFWorkbook workbook;
using (var fs = new FileStream(tmpl.FullName, FileMode.Open, FileAccess.Read))
{
    workbook = new HSSFWorkbook(fs);
}

int rowIndex = 1;
var sheetProducts = workbook.GetSheetAt(0);
foreach (var product in products)
{
    var productDataRow = sheetProducts.CreateRow(rowIndex);
    productDataRow.CreateCell(0).SetCellValue(product.ProductId);
    productDataRow.CreateCell(1).SetCellValue(product.Code);
    productDataRow.CreateCell(2).SetCellValue(product.RetailerCode);
    productDataRow.CreateCell(3).SetCellValue(product.BrandId);
    productDataRow.CreateCell(4).SetCellValue(product.ColorId);
    productDataRow.CreateCell(5).SetCellValue(product.GenreId);
    productDataRow.CreateCell(6).SetCellValue(product.MarketplaceId);
    productDataRow.CreateCell(7).SetCellValue(product.MarketplaceStyleCode);

    rowIndex++;
}

MemoryStream output = new MemoryStream();
workbook.Write(output);

return new FileContentResult(output.ToArray(), "application/vnd.ms-excel")
{
    FileDownloadName = $"{DateTime.UtcNow.ToString("yyyyMMdd-HHmmss")}-{client.Url}-{tmpl.Name}"
};

And in the import process i use the mapper.take in order to read the file rows

var workbook = new HSSFWorkbook(file.InputStream);
var mapper = new Npoi.Mapper.Mapper(workbook);
var productsExcelRows = mapper.Take<ProductMappingExcelRow>(0);

The ProductMappingExcelRow is defined as follow

public class ProductMappingExcelRow
{
    [Display(Name = "ID")]
    public string ProductId { get; set; }

    [Display(Name = "Product Code")]
    public string Code { get; set; }

    [Display(Name = "Retailer Code")]
    public string RetailerCode { get; set; }

    [Display(Name = "Brand")]
    public string BrandId { get; set; }

    [Display(Name = "Color")]
    public string ColorId { get; set; }

    [Display(Name = "Genre")]
    public string GenreId { get; set; }

    [Display(Name = "Marketplace ID")]
    public string MarketplaceId { get; set; }

    [Display(Name = "Marketplace Style Code")]
    public string MarketplaceStyleCode { get; set; }
}

Even if i set dynamic type in the mapper, all rows properties has null value mapper.Take<dynamic>(0)

Specifically, each row has the following ErrorMessage "System.MissingMethodException: Impossibile trovare il metodo 'System.DateTime NPOI.SS.UserModel.ICell.get_DateCellValue()"

smithlogi commented 3 months ago

+1

SAPHemlock commented 1 month ago

Facing the same issue in .net framework 4.8 based asp.net mvc project. I am trying to read data from excel having string and decimal data but all string cells returned as null and numeric cells as zero. Having latest nuget packages as of Sep'24 where the issue still persist.

sbaylov commented 1 week ago

Having the same issue with the latest version of Mapper (6.2.1): System.MissingMethodException: Method not found: 'System.DateTime NPOI.SS.UserModel.ICell.get_DateCellValue()'. at Npoi.Mapper.MapHelper.TryGetCellValue(...) at Npoi.Mapper.Mapper.LoadRowData(...) Is there a way to resolve that ?