Set number format in pivot

Hi Team,


How do i set a pivot column as number format?
In the attached file, how do I make column Original Forecast Quantity as number format.

We are using Aspose 8.3.0

Thanks,
Sukesh

Hi Sukesh,

Thanks for your posting, video file and using Aspose.Cells.

If you want to set Built-in Number format, then use PivotField.setNumber() method and if you want to set Custom Number format, then use PivotField.setNumberFormat() method.

Please see the following sample code. It sets the built-in number format i.e 4 to get the desired results as shown in your video. I have attached the output Excel file generated by the code for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\Forecast Set Items_1013415_44_1.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.getWorksheets().get(1);


PivotTable pivot = worksheet.getPivotTables().get(0);


//Number 4 is a built-in format

pivot.getDataFields().get(1).setNumber(4);


//If you use some custom format then use

// pivot.getDataFields().get(1).setNumberFormat("");


workbook.save(“output.xlsx”);

Hi Shakeel,


The fix you provided is working for us. Thanks for the help.

Thanks,
Sukesh

Hi Sukesh,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved with the given code. Let us know if you encounter any other issue, we will be glad to look into it and help you further.