从工作表中删除数据透视表
Contents
[
Hide
]
Aspose.Cells 提供了从工作表中删除或删除数据透视表的功能。您可以使用数据透视表对象或数据透视表位置删除数据透视表。请使用工作表.数据透视表.Remove()使用数据透视表对象删除数据透视表的方法和工作表.数据透视表.RemoveAt()使用其在数据透视表集合中的位置删除数据透视表对象的方法。
以下示例代码从工作表中删除两个数据透视表。首先,它使用删除数据透视表工作表.数据透视表.Remove()方法,然后它使用删除数据透视表工作表.数据透视表.RemoveAt()方法
This file contains hidden or 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"); |