0

Got an error in aspnet zero ExcelExporter class. "The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly."

NpoiExcelExporterBase.AddObjects(ISheet, IList, params Func<T, object>[])

 public FileDto ExportToFile(List<GetProductForViewDto> products)
        {
            return CreateExcelPackage(
                "Products.xlsx",
                excelPackage =>
                {

                    var sheet = excelPackage.CreateSheet(L("Products"));

                    AddHeader(
                        sheet,
                        L("Model"),
                        L("PartNo"),
                        L("Description"),
                        L("UnitOfMeasure"),
                        L("Barcode"),
                        (L("Category")) + L("Description"),
                        (L("Brand")) + L("Description")
                        );

                    AddObjects(
                        sheet, 2, products,
                        _ => _.Product.Model,
                        _ => _.Product.PartNo,
                        _ => _.Product.Description,
                        _ => _.Product.UnitOfMeasure,
                        _ => _.Product.Barcode,
                        _ => _.CategoryDescription,
                        _ => _.BrandDescription
                        );

                });
        }

Can anybody help why is this happening. I think I miss something in AddObjects Parameter.

Thanks

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
comfreakph
  • 549
  • 2
  • 6
  • 20

1 Answers1

0

This is the correct code

             AddObjects(
                    sheet, products,
                    _ => _.Product.Model,
                    _ => _.Product.PartNo,
                    _ => _.Product.Description,
                    _ => _.Product.UnitOfMeasure,
                    _ => _.Product.Barcode,
                    _ => _.CategoryDescription,
                    _ => _.BrandDescription
             );
comfreakph
  • 549
  • 2
  • 6
  • 20