Hi, by default when creating pivot tables in Excel every row items are expanded showing the drilldown items in the succeeding row item fields. How do I select a specific row item or multiple row items in a particular row field in the pivot and then collapse the drilldown. Appreciate if you could provide a sample code, thanks.
You can find the PivotItem that need to be hidden by traversing the PivotField’s PivotItems collection.
If you are using Aspose.Cells for Python via JAVA, you can control whether to hide details through the PivotItem.setHideDetail(value) method.
If you are using Aspose.Cells for Python via NET, you can use PivotItem.is_hide_detail property to control whether to hide details.
Hope helps a bit.
Sample code for Python via Net:
import aspose.cells from aspose.cells import Workbook, PdfSaveOptions book = Workbook("pivot.xlsx") pivot = book.worksheets.pivot_tables rowField = pivot.row_fields rowField.pivot_items.is_hide_detail = True pivot.refresh_data_flag = True pivot.refresh_data() pivot.calculate_data() pivot.refresh_data_flag = False book.save("out_python_net.xlsx")
Hope helps a bit.
I tried using Python via Java since this is what we’re using, but I’m having an object has no attribute error kindly correct my code
PivotField = PivotTable.getRowFields().get(0)
PivotItem = PivotField.getPivotItems().get(0)
Attribute Error message:
‘com.aspose.cells.PivotItem’ object has no attribute ‘setHideDetail’
Our version of aspose-cells is 21.6.0, are there similar setHideDetail function in the older versions as a work around or is this function added just recently?
There is no alternative to setHideDetail method, so you have to upgrade to latest APIs set for availing maximum features and other enhancements.