用 Node.js 通过 C++ 删除工作簿中的未使用样式
Contents
[
Hide
]
未使用的样式不仅占用空间,还会在转换为PDF、HTML等不同格式时引发性能问题。Aspose.Cells提供了Workbook.removeUnusedStyles()以删除工作簿内所有未使用的样式。
以下代码说明了Workbook.removeUnusedStyles()的用法。该代码加载了模板Excel文件,可以通过提供的链接下载。它包含一个名为AsposeStyle的未使用样式;执行后,此样式及所有其他未使用样式将被删除。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Template-With-Unused-Custom-Style.xlsx");
// Load template excel file containing unused styles
const workbook = new AsposeCells.Workbook(filePath);
// 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
workbook.save(path.join(dataDir, "output_out.xlsx"));