用C++格式化切片器
Contents
[
Hide
]
可能的使用场景
你可以通过设置其列数或样式等来格式化Excel中的切片器。Aspose.Cells还允许你使用Slicer.GetNumberOfColumns()和Slicer.GetStyleType()属性实现此操作。
格式化切片器
请查看以下代码示例;它加载包含切片器的示例Excel文件,访问切片器并设置其列数和样式类型,然后另存为输出Excel文件。截图展示了执行示例代码后,切片器的样子。
示例代码
#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 slicer.
Workbook workbook(u"sampleFormattingSlicer.xlsx");
// Access first worksheet.
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Access the first slicer inside the slicer collection.
Slicer slicer = worksheet.GetSlicers().Get(0);
// Set the number of columns of the slicer.
slicer.SetNumberOfColumns(2);
// Set the type of slicer style.
slicer.SetStyleType(SlicerStyleType::SlicerStyleLight6);
// Save the workbook in output XLSX format.
workbook.Save(u"outputFormattingSlicer.xlsx", SaveFormat::Xlsx);
std::cout << "Slicer formatted and workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}