Hi,
Hi Willem,
Thank you for reporting this problem.
I have evaluated the presented issue with your provided sample project and spreadsheet while using the latest version of Aspose.Cells for .NET 7.6.0.7. I have noticed that removing one field removes the other as well, that is an incorrect behavior, and therefore needs to be investigated. A ticket (CELLSNET-42149) has been logged in our bug tracking system to look further into this matter. Please spare us little time to properly analyze the problem cause, and to provide a fix for this situation. In meanwhile, we will keep you posted with updates in this regard.
Please accept our apologies for your inconvenience.
Hi,
Thanks for the quick reply.
Hi,
Thanks i can use that, but now i have another strange behavior:
i have one datafield, then i remove all datafields, then i add the same datafield again somehow the datafield is now twice added. This only happens with one datafield, if there are more datafields and i remove them and add them again it works fine.
Hi,
Thanks,
Hi,
Hi,
Hi Willem-Jan,
Hi,
Please download and try our latest version/fix: Aspose.Cells for .NET v7.7.0.2
We have fixed this issue.
· There are some
points for attention though:
-
PageFields attribute of PivotTable specifies a collection of PivotField in page or filter label area. RowFields attribute of PivotTable specifies a collection of PivotField in row label area. ColumnFields attribute of PivotTable specifies a collection of PivotField in column label area. DataFields attribute of PivotTable specifies a collection of PivotField in data label area. DataField attribute of PivotTable exists only if DataFields contains two or more PivotField.
-
DataField is a virtual PivotField, which can be placed in Column label area or Row label area.
-
If you want to remove a PivotField, you have the following three ways:
First, using the method RemoveField(PivotFieldType fieldType, string fieldName).
Second, using the method RemoveField(PivotFieldType fieldType, int baseFieldIndex).
Third, using the method RemoveField(PivotFieldType fieldType, PivotField pivotField).
But if you use the method RemoveField(PivotFieldType fieldType, PivotField pivotField), there are some points to be noted. If the second parameter pivotField is DataField attribute of PivotTable, you will remove all the PivotField in DataFields. If you do it like this in MS Excel, you will get the same result. So the code in sample project should be as follows:
if (pivotTable.DataField != null)
{
pivotTable.RemoveField(PivotFieldType.Data, pivotTable.DataField);
}
pivotTable.AddFieldToArea(PivotFieldType.Data, "Betrag Netto FW");
As a result of the count of DataFields is one, so DataField attribute of PivotTable is null, if block will not be executed. So, when you add a PivotField existed in DataFields to Data label area, it is added twice.
- For the problem, “There’s already data in […]Sheet1. Do you want to replace it?”
Please change the codes accordingly:
e.g.
pivotTable.AddFieldToArea(PivotFieldType.Data, "Betrag Netto FW");
pivotTable.AddFieldToArea(PivotFieldType.Data, "Menge");
to:
pivotTable.AddFieldToArea(PivotFieldType.Data, "Betrag Netto FW");
pivotTable.AddFieldToArea(PivotFieldType.Data, "Menge");
pivotTable.RefreshDataFlag = true;
as a result of the default position of DataField is in row label area, so if you want to get the same result like source file, you should use the codes as follows:
pivotTable.AddFieldToArea(PivotFieldType.Data, "Betrag Netto FW");
pivotTable.AddFieldToArea(PivotFieldType.Data, "Menge");
pivotTable.AddFieldToArea(PivotFieldType.Column, pivotTable.DataField);// add DataField to column label area
pivotTable.RefreshDataFlag = true;
Hope, this helps a bit.
Thank you.
Hi,
Hi Willem-Jan,
Hi,
sheet.Cells.ClearRange(pivotTable.ColumnRange);
sheet.Cells.ClearRange(pivotTable.DataBodyRange);
Hi,
Hi Willem-Jan,
Hi,
pivotTable.RefreshData();
pivotTable.CalculateData();
Hi,
Hi Willem-Jan,