删除工作簿中的未使用样式
Contents
[
Hide
]
Excel文件中的未使用样式不仅占用空间,还会在转换为PDF、HTML等不同格式时引起性能问题。Aspose.Cells for Python via .NET提供了Workbook.remove_unused_styles()方法,用于移除工作簿内所有未使用的样式。
下面的代码解释了Workbook.remove_unused_styles()的用法。该代码加载了可以从提供的链接下载的模板Excel文件。它包含一个名为AsposeStyle的未使用样式,此样式和所有其他未使用的样式将在执行代码后被移除。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Load template excel file containing unused styles | |
workbook = Workbook(dataDir + "Template-With-Unused-Custom-Style.xlsx") | |
# Remove all unused styles inside the template this will also remove AsposeStyle which is an unused style inside the template | |
workbook.remove_unused_styles() | |
# Save the file | |
workbook.save(dataDir + "output_out.xlsx") |