I would like to sort an Excel pivot table created by using the win32com module with Python.
As I understood, I should use the function AutoSort() and according to the official documentation, there are four fields, two of which are optional. Therefore, I am specifying only the "Order" and "Field" fields.
AutoSort(Order=1, Field="Tot Converted Amount Due")
However, when I run the below line of code, I get an error.
wb.Sheets("pivot_table").PivotTables("pivot_table").PivotFields("Tot Converted Amount Due").AutoSort(Order=1, Field="Tot Converted Amount Due")
Error:
def AutoSort(self, Order=defaultNamedNotOptArg, Field=defaultNamedNotOptArg, PivotLine=defaultNamedOptArg, CustomSubtotal=defaultNamedOptArg):
---> 44 return self._oleobj_.InvokeTypes(1514, LCID, 1, (24, 0), ((3, 1), (8, 1), (12, 17), (12, 17)),Order
45 , Field, PivotLine, CustomSubtotal)
46
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146827284), None)
What am I doing wrong?
I would really appreciate any inputs or help. Thanks!
from Sorting a pivot table with win32com using Python
No comments:
Post a Comment