Cells 25.4创建数据透视表问题

数据透视表,没有列,只有筛选器、行和两个值。生成的数据透视表里,值是多行展示,如何实现按列展示?自动把“数值”挪到列中
image.jpg (115.6 KB)

另外,基于透视表创建出来的透视图,不像正常的透视图一样,可以看到透视表的相关信息,在数据透视表分析下面没有任何可操作项?什么原因?
image.jpg (159.8 KB)

image.jpg (123.7 KB)

@YU_tou

Cause

It seems that your pivot table is currently set up with values displayed in multiple rows instead of columns. This typically happens when the pivot table configuration does not include the necessary fields in the column area.

Solution

To display values in columns instead of rows, you need to adjust the pivot table’s field settings. Specifically, you should drag the desired value fields into the “Columns” area of the pivot table configuration.

Code

Here’s a basic example of how to create a pivot table and set the fields appropriately using Aspose.Cells:

// Create a new workbook and get the first worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

// Add some sample data
worksheet.Cells["A1"].PutValue("Category");
worksheet.Cells["B1"].PutValue("Value");
worksheet.Cells["A2"].PutValue("A");
worksheet.Cells["B2"].PutValue(10);
worksheet.Cells["A3"].PutValue("B");
worksheet.Cells["B3"].PutValue(20);
worksheet.Cells["A4"].PutValue("A");
worksheet.Cells["B4"].PutValue(30);

// Create a pivot table
int pivotTableIndex = worksheet.PivotTables.Add("=A1:B4", "D1", "PivotTable1");
PivotTable pivotTable = worksheet.PivotTables[pivotTableIndex];

// Add fields to the pivot table
pivotTable.AddFieldToArea(PivotFieldType.Row, 0); // Category
pivotTable.AddFieldToArea(PivotFieldType.Data, 1); // Value
pivotTable.AddFieldToArea(PivotFieldType.Column, 0); // Move Value to Columns

// Refresh the pivot table
pivotTable.RefreshData();

Next Steps

  1. Adjust your pivot table configuration to include the value fields in the “Columns” area.
  2. Refresh the pivot table to see the changes reflected.
  3. If you still do not see the expected options under the PivotTable Analyze tab, ensure that the pivot table is correctly selected and that you are using the latest version of Aspose.Cells.

Please implement these changes, and let me know if you need further assistance!

机器人人不要乱回答!!!!

@YU_tou

PivotTable.DataField对象表示数据透视表中的所有数据字段。它是只读的。只有当数据区域中有两个或多个数据字段时,才会创建它。默认情况下,它位于行区域。您可以使用AddFieldToArea()方法将其拖动到数据透视表的行/列区域。

请在添加完所有数据字段后,使用以下代码拖动PivotTable.DataField对象到指定的区域。

pivotTable.AddFieldToArea(PivotFieldType.Column, pivotTable.DataField);

你愿意提供样例文件,代码运行的结果文件,期望的excel文件和可运行的测试代码吗?我们很快就会检查。