Aspose cells Java PivotTable Field Settings -> Repeat item labels

Hi, I have requirement where I need to check or un-check “Repeat Item Labels” setting in “Filed Settings” menu in Excel Pivot Table. For your reference I am enclosing the screenshot. Please let me know sample code to achieve this functionality. I don’t have code sample now, so unable to share. Please do needful. Enclosed sample excel file too.
Reports_List-Copy.zip (180.0 KB)

pivot field settings - repeat item labels.png (297.4 KB)

@koteswaragunda,

Thanks for the sample file and screenshot.

You may try to use PivotField.setRepeatItemLabels() method. See the following sample code on how to check the property for a pivot field in your sample file and it works fine as I tested.
e.g.,
Sample code:

Workbook workbook = new Workbook("d:\\files\\Reports_List-Copy.xlsx");
//Get the pivot table
PivotTable pivot = workbook.getWorksheets().get("Reports Lis").getPivotTables().get(0);
//get column PivotField collection
PivotFieldCollection cols = pivot.getColumnFields();
//get specific colmn PivotField using its name
PivotField field = cols.get("Business Application");

//set RepeatItemLabels is true
field.setRepeatItemLabels(true);
workbook.save("d:\\files\\out1.xlsx");

Hope, this helps a bit.

@amjad.sahi

It helped. Thank You.

Small question, suppose I have 10 columns then I need to write a loop to set this flag in each column field or row field?
(or) is there any easy method to apply this flag on entire row field collection or column field collection?

@koteswaragunda,

Yes, you need to loop through pivot fields and set this attribute on for each pivot field.

@amjad.sahi Thank you.

@koteswaragunda,

You are welcome.