[英]ListAggregatorFactory returns system.collections.generic.list`1[system.object]
I've been using the powerful NReco library to create pivot tables.我一直在使用功能强大的 NReco 库创建 pivot 个表。 And using the very convenient HTML wrapper extension to turn those tables into HTML. When I use the '' I get the following returned into the HTML.
并使用非常方便的 HTML 包装器扩展将这些表转换为 HTML。当我使用 '' 时,我将以下内容返回到 HTML。
System.Collections.Generic.List`1[System.Object]
System.Collections.Generic.List`1[System.Object]
The error seems very straight-forward.该错误似乎非常简单。 The HTML wrapper is probably just calling
ToString()
on the collection object rather then joining the list. HTML 包装器可能只是在集合 object 上调用
ToString()
而不是加入列表。 Is there a way to override the HTML wrappers functionality when it comes to formatting this list.在格式化此列表时,有没有办法覆盖 HTML 包装器功能。
I assume you mean pivot table writers (like PivotTableHtmlWriter
) from NReco.PivotData.Extensions nuget package.我假设你的意思是来自 NReco.PivotData.Extensions nuget package 的 pivot 表编写器(如
PivotTableHtmlWriter
)。
You're right with your suggestion that by default aggregator's value is simply converted to string with object.ToString()
call.您的建议是正确的,默认情况下聚合器的值只是通过
object.ToString()
调用转换为字符串。 This works good for simple values, however for complex objects (including lists) there are no default representation - this motivates to define your own 'value-formatter' handler and don't rely on any default conventions:这适用于简单的值,但是对于复杂的对象(包括列表)没有默认表示 - 这会激发您定义自己的“值格式化程序”处理程序并且不依赖任何默认约定:
pvtHtmlWr.FormatValue = (aggr,measureIdx) => {
if (aggr.Count==0)
return String.Empty;
if (aggr.Value is IList) {
var ls = (IList)aggr.Value;
var sb = new StringBuilder();
for (int i=0; i<ls.Count; i++) {
var entryStr = Convert.ToString( ls[i] ); // or apply custom formatting of list entries
if (entryStr.Length>0) {
if (sb.Length>0)
sb.Append(", ");
sb.Append(entryStr);
}
}
return sb.ToString();
}
// apply default number format
return String.Format("{0:0.##}", aggr.Value);
};
More on pivot table values formatting: https://www.nrecosite.com/pivotdata/format-pivot-table.aspx有关 pivot 表值格式的更多信息: https://www.nrecosite.com/pivotdata/format-pivot-table.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.