Original code |
Modified code |
IPivotCache cache = workbook.PivotCaches.Add(worksheet[iDatStart, 1, iLine - 1, iMax]);
IPivotTable pivotTable = pivotWs.PivotTables.Add("SUM", pivotWs[1, 1], cache);
pivotTable.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium2;
//pivotTable.Fields[1].Axis = PivotAxisTypes.Page;
pivotTable.Fields[1].Axis = PivotAxisTypes.Row; pivotTable.Fields[9].Axis = PivotAxisTypes.Row; pivotTable.Fields[15].Axis = PivotAxisTypes.Column; IPivotField field = pivotTable.Fields[19];
pivotTable.DataFields.Add(field, "SUM", PivotSubtotalTypes.Sum); field.NumberFormat = "#,##0.00 "; worksheet.Calculate();
IPivotField field2 = pivotTable.Fields[19];
IPivotDataField dfSum2 = pivotTable.DataFields.Add(field2, "SUM%", PivotSubtotalTypes.Sum); dfSum2.ShowDataAs = PivotFieldDataFormat.PercentageOfColumn;
field2.NumberFormat = "#,##0.00% "; worksheet.Calculate(); |
IPivotCache cache = workbook.PivotCaches.Add(worksheet[iDatStart, 1, iLine - 1, iMax]);
IPivotTable pivotTable = pivotWs.PivotTables.Add("SUM", pivotWs[1, 1], cache);
pivotTable.BuiltInStyle = PivotBuiltInStyles.PivotStyleMedium2;
//pivotTable.Fields[1].Axis = PivotAxisTypes.Page;
pivotTable.Fields[1].Axis = PivotAxisTypes.Row; pivotTable.Fields[9].Axis = PivotAxisTypes.Row; pivotTable.Fields[15].Axis = PivotAxisTypes.Column; PivotCacheFieldsCollection pivotCaches = (pivotTable as PivotTableImpl).Cache.CacheFields;
(pivotTable.Fields[19] as PivotFieldImpl).IsDataField = true;
IPivotField field = new PivotFieldImpl(pivotCaches[19], pivotTable as PivotTableImpl);
pivotTable.DataFields.Add(field, "SUM", PivotSubtotalTypes.Sum); field.NumberFormat = "#,##0.00 "; worksheet.Calculate();
IPivotField field2 = new PivotFieldImpl(pivotCaches[19], pivotTable as PivotTableImpl);
IPivotDataField dfSum2 = pivotTable.DataFields.Add(field2, "SUM%", PivotSubtotalTypes.Sum); dfSum2.ShowDataAs = PivotFieldDataFormat.PercentageOfColumn;
field2.NumberFormat = "#,##0.00% "; worksheet.Calculate(); |