使用C++移除工作簿中的未使用样式
Contents
[
Hide
]
未使用的样式不仅占用空间,还会在转换为PDF、HTML等不同格式时引发性能问题。Aspose.Cells提供了Workbook.RemoveUnusedStyles()以删除工作簿内所有未使用的样式。
以下代码说明了Workbook.RemoveUnusedStyles()的用法。该代码加载了模板Excel文件,可以通过提供的链接下载。它包含一个名为AsposeStyle的未使用样式;执行后,此样式及所有其他未使用样式将被删除。
#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
// Path to the documents directory.
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Load template Excel file containing unused styles
U16String templateFilePath = srcDir + u"Template-With-Unused-Custom-Style.xlsx";
Workbook workbook(templateFilePath);
// Remove all unused styles inside the template
// This will also remove AsposeStyle which is an unused style inside the template
workbook.RemoveUnusedStyles();
// Save the file
U16String outputFilePath = srcDir + u"output_out.xlsx";
workbook.Save(outputFilePath);
std::cout << "Unused styles removed and file saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}