Aspose.Cells.Examples.CSharp.Articles.PivotTablesAndPivotCharts.RemovePivotTable.Run C# (CSharp) Method

Run() public static method

public static Run ( ) : void
return void
        public static void Run()
        {
            // ExStart:RemovePivotTableFromWorksheet
            // 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");
            // ExEnd:RemovePivotTableFromWorksheet
        }
    }
RemovePivotTable