Change Slicer Properties with C++
Possible Usage Scenarios
There might be situations where you may want to change the properties of the Slicer such as placement or row height. Aspose.Cells provides you with the option to update these properties.
Change Slicer Properties
Please see the following sample code. It loads the sample Excel file that contains a table. It then creates the slicer based on the first column and changes its properties like row height, width, is printable, title, etc. It saves the workbook as outputChangeSlicerProperties.xlsx.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Load sample Excel file containing a table.
U16String sourceDir(u"..\\Data\\01_SourceDirectory\\");
U16String outputDir(u"..\\Data\\02_OutputDirectory\\");
Workbook workbook(sourceDir + u"sampleCreateSlicerToExcelTable.xlsx");
// Access first worksheet.
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Access first table inside the worksheet.
ListObject table = worksheet.GetListObjects().Get(0);
// Add slicer
int32_t idx = worksheet.GetSlicers().Add(table, 0, u"H5");
Slicer slicer = worksheet.GetSlicers().Get(idx);
slicer.SetPlacement(PlacementType::FreeFloating);
slicer.SetRowHeightPixel(50);
slicer.SetWidthPixel(500);
slicer.SetTitle(u"Aspose");
slicer.SetAlternativeText(u"Alternate Text");
slicer.SetIsPrintable(false);
slicer.SetIsLocked(false);
// Refresh the slicer.
slicer.Refresh();
// Save the workbook in output XLSX format.
workbook.Save(outputDir + u"outputChangeSlicerProperties.xlsx", SaveFormat::Xlsx);
Aspose::Cells::Cleanup();
return 0;
}