![](/img/trans.png)
[英]How can I order/sort a PivotTable based on the contents of a DataField PivotField?
[英]How can I list a pivotfield with orientation xlColumnField in a specific custom order in C#
Excel.PivotField pf = (Excel.PivotField)pvtTable.PivotFields("Sport");
//Desired list order.
List<string> oListOrder = new List<string>() { "Football", "Tennis", "Baseball", "Softball" };
foreach (Excel.PivotItem pi in pf.PivotItems()) {
//Get index in desired list order.
int idx = oColumnSort.IndexOf(pi.Name);
//If PivotItem in ordered list set PivotItem position to that of list.
//Add 1 bc Position & List have different starting base.
if (idx >= 0) pi.Position = idx + 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.