Removing Slicer with C++
Possible Usage Scenarios
If you want to remove a slicer in Microsoft Excel, just select it and press the Delete button. Similarly, if you want to remove it using Aspose.Cells API programmatically, please use the Worksheet.Slicers.Remove() method. It will remove the slicer from the worksheet.
Removing Slicer
The following sample code loads the sample Excel file that contains an existing slicer. It accesses the slicers and then removes it. Finally, it saves the workbook as output Excel file. The following screenshot shows the slicer that will be removed after the execution of the sample code.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Load sample Excel file containing slicer.
U16String inputFilePath(u"sampleRemovingSlicer.xlsx");
Workbook wb(inputFilePath);
// Access first worksheet.
WorksheetCollection worksheets = wb.GetWorksheets();
Worksheet ws = worksheets.Get(0);
// Access the first slicer inside the slicer collection.
SlicerCollection slicers = ws.GetSlicers();
Slicer slicer = slicers.Get(0);
// Remove slicer.
slicers.Remove(slicer);
// Save the workbook in output XLSX format.
U16String outputFilePath(u"outputRemovingSlicer.xlsx");
wb.Save(outputFilePath, SaveFormat::Xlsx);
std::cout << "Slicer removed successfully!" << std::endl;
Aspose::Cells::Cleanup();
}