【问题标题】:The type arguments for method cannot be inferred from the usage. Try specifying the type arguments explicitly. Aspnet Zero ExcelExporter error无法从用法中推断出方法的类型参数。尝试明确指定类型参数。 Aspnet 零 ExcelExporter 错误
【发布时间】:2021-11-19 07:29:14
【问题描述】:

在 aspnet 零 ExcelExporter 类中出现错误。 “无法从用法中推断出方法的类型参数。请尝试显式指定类型参数。”

NpoiExcelExporterBase.AddObjects(ISheet, IList, params Func[])

 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
                        );

                });
        }

任何人都可以帮助为什么会发生这种情况。我想我错过了 AddObjects 参数中的某些内容。

谢谢

【问题讨论】:

  • 2 有什么用?它似乎不适合方法签名
  • 让我检查一下,我认为这可能是原因

标签: c# excel npoi


【解决方案1】:

这是正确的代码

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多