从工作表中删除数据透视表
Contents
[
Hide
]
Aspose.Cells for Python via .NET 提供了从工作表中删除数据透视表的功能。您可以使用数据透视表对象或数据透视表位置来删除数据透视表。请使用 Worksheet.pivot_tables.remove(pivot_table) 方法使用数据透视表对象删除数据透视表,并使用 Worksheet.pivot_tables.remove_at(index, keep_data) 方法根据数据透视表集合中的位置来删除数据透视表对象。
使用Aspose.Cells for Python Excel库删除工作表中的数据透视表
以下示例代码从工作表中删除了两个数据透视表。首先使用Worksheet.pivot_tables.remove(pivot_table)方法移除数据透视表,然后使用Worksheet.pivot_tables.remove_at(index, keep_data)方法移除数据透视表。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create workbook object from source Excel file | |
workbook = Workbook(dataDir + "source.xlsx") | |
# Access the first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access the first pivot table object | |
pivotTable = worksheet.pivot_tables[0] | |
# Remove pivot table using pivot table object | |
worksheet.pivot_tables.remove(pivotTable) | |
# OR you can remove pivot table using pivot table position by uncommenting below line | |
# worksheet.PivotTables.RemoveAt(0); | |
# Save the workbook | |
workbook.save(dataDir + "output_out.xlsx") |