Problem with PivotTable.SetManualGroupField

hello


This is my code:

Worksheet arkusz3Grupowanie=excel.Worksheets.Add(“Arkusz 3”);
PivotTableCollection pivTabGrup = arkusz3Grupowanie.PivotTables;

int indeksPivGrup=pivTabGrup.Add("=Arkusz1!Q3:S503", “B2”, “pivGrup”);

PivotTable pivotTableGrup = pivTabGrup[indeksPivGrup];

pivotTableGrup.IsAutoFormat = true;

pivotTableGrup.AddFieldToArea(PivotFieldType.Row, “sprzedaż”);
pivotTableGrup.AddFieldToArea(PivotFieldType.Data, “nazwa produktu”);
ArrayList list = new ArrayList();
list.Add(PivotGroupByType.RangeOfValues);

pivotTableGrup.SetManualGroupField(0,100,800,list,50);

excel.Save(path);


After compiling I get error “Invalid pivot field index” in line marked red.I am not sure but the method SetManualGroupField use the PivotTable.BaseFields in which I have two fields and i do not know why the error occurs.
Thanks for answer

part of my table

nazwa produktu kategoria sprzedaż
produkt 1 A 925
produkt 2 A 617
produkt 3 A 82
produkt 4 A 347

Ok I fixed it. I didnt get an object from BaseFields but from RowFields.


pivotTableGrup.AddFieldToArea(PivotFieldType.Row, “sprzedaż”);
pivotTableGrup.AddFieldToArea(PivotFieldType.Data, “nazwa produktu”);

var w = pivotTableGrup.RowFields;

var s = pivotTableGrup.BaseFields;
PivotField sprzedaz = pivotTableGrup.RowFields[0];
ArrayList list = new ArrayList();
list.Add(PivotGroupByType.RangeOfValues);
pivotTableGrup.SetManualGroupField(w[0], 100, 800, list, 50);



And I have a question. Why I can not use BaseFields, it should contain all Fields I put into my pivot table

Hi,

Thanks for your posting and using Aspose.Cells.

Yes, all fields should be found in the base fields. Please provide us your sample console application project replicating this issue with the latest version: Aspose.Cells for .NET 8.5.0 so that we could look into this issue at our end. We will investigate it and update you asap.