已接管了使用ClosedXML的旧项目。产生错误的方法使用
IEnumerable<MainObject> rows
并为其创建工作表。但是存在另一个属性>
执行IEnumerable<Object1>
在MainObject中。该代码通过
worksheet.Cell(startRow, 1).InsertTable(rows);
并且这样做的时候我得到
An unhandled exception has occurred: Unable to set cell value to System.Collections.Generic.List`1[Object1] System.ArgumentException: Unable to set cell value to System.Collections.Generic.List`1[Object1]
我的猜测是,我必须创建另一个(重写?)InsertTable,它使用反射来调用正确的类型,然后甚至在IEnumerable属性上使用InsertTable。但是有可能在重写函数中使用某种递归调用并跳过所有自定义映射?
任何想法或建议都很好。
已接管了使用ClosedXML的旧项目。创建错误的方法采用IEnumerable
ClosedXML不知道如何处理每一行的内部Object1
。如果您创建自己的POCO对象的IEnumerable<>
并在其上调用InsertTable
,例如[>
var pocos = rows.Select(m => new { m.Property1, m.Property2, m.Object1.OtherProperty });
worksheet.Cell(startRow, 1).InsertTable(pocos);