Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

excel - Aspose.Cells .Net C# 'Σ Values' shown in Row for pivot table

I'm using Aspose.Cells to create an Excel spreadsheet and adding a PivotTable into that spreadsheet but the 'Σ Values' gets added into the Rows and I want it into the Columns. The code sample is shown below

Aspose.Cells.Pivot.PivotTableCollection pivotTables = sheet.PivotTables;

// Adding a PivotTable to the worksheet
int index = pivotTables.Add("=A1:D8", "H3", "PivotTable2");

// Accessing the instance of the newly added PivotTable
Aspose.Cells.Pivot.PivotTable pivotTable = pivotTables[index];

// Unshowing grand totals for rows and collapsing.
pivotTable.RowGrand = false;
// Setting the PivotTable report is automatically formatted
pivotTable.IsAutoFormat = true;

// Setting the PivotTable atuoformat type.
pivotTable.AutoFormatType = Aspose.Cells.Pivot.PivotTableAutoFormatType.Report4;

// Draging the fields to the row area.
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 0);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, 1);

// Draging the third field to the data area.
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, 2);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, 3);

// collapsing
sheet.PivotTables[0].RowFields[0].HideDetail(true);

The sample code produces this pivottable

While simply dragging the 'Σ Values' field from Rows to Columns produces the desired PivotTable, as shown below.

Using Excel to drag 'Σ Values' from Rows to Columns

How can I get the 'Σ Values' field into the Columns area using code?

Cheers Steve


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...