从工作表中删除数据透视表
Contents
[
Hide
]
Aspose.Cells提供了一个功能,用于删除或移除工作表中的数据透视表。您可以使用数据透视表对象或数据透视表位置来删除数据透视表。请使用Worksheet.PivotTables.Remove()方法使用数据透视表对象来删除数据透视表,使用其位置在数据透视表集合内Worksheet.PivotTables.RemoveAt()方法删除数据透视表对象。
以下示例代码从工作表中删除了两个数据透视表。首先使用Worksheet.PivotTables.Remove()方法移除数据透视表,然后使用Worksheet.PivotTables.RemoveAt()方法移除数据透视表。
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object from source Excel file | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the first pivot table object | |
PivotTable pivotTable = worksheet.PivotTables[0]; | |
// Remove pivot table using pivot table object | |
worksheet.PivotTables.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"); |