调整工作簿压缩级别
Contents
[
Hide
]
调整工作簿压缩级别
在处理较大的工作簿时,开发人员可以调整工作簿的压缩级别。开发人员可能会优先考虑较小的文件大小而不是处理时间,反之亦然。 Aspose.Cells提供**OoxmlCompressionType**可用于设置工作簿压缩级别的枚举。这**OoxmlCompressionType**枚举提供以下成员。
- Level1:最快但效率最低的压缩。
- Level2:比 Level 1 慢一点,但更好。
- Level3:比 Level 2 慢一点,但更好。
- Level4:比 Level 3 慢一点,但更好。
- Level5:比 Level 4 慢一点,但压缩效果更好。
- Level6:速度和压缩效率的良好平衡。
- Level7:相当不错的压缩!
- Level8:压缩比 Level7 更好!
- 级别 9:“最佳”压缩,其中最佳意味着输入数据流大小的最大减少。这也是最慢的压缩。
下面的代码片段演示了使用**OoxmlCompressionType**枚举并比较 Level1、Level6 和 Level9 的转换时间。您还可以比较生成的文件的大小。
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
string outDir = RunExamples.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "LargeSampleFile.xlsx"); | |
XlsbSaveOptions options = new XlsbSaveOptions(); | |
options.CompressionType = OoxmlCompressionType.Level1; | |
var watch = System.Diagnostics.Stopwatch.StartNew(); | |
workbook.Save(outDir + "LargeSampleFile_level_1_out.xlsb", options); | |
watch.Stop(); | |
var elapsedMs = watch.ElapsedMilliseconds; | |
Console.WriteLine("Level 1 Elapsed Time: " + elapsedMs); | |
watch = System.Diagnostics.Stopwatch.StartNew(); | |
options.CompressionType = OoxmlCompressionType.Level6; | |
workbook.Save(outDir + "LargeSampleFile_level_6_out.xlsb", options); | |
watch.Stop(); | |
elapsedMs = watch.ElapsedMilliseconds; | |
Console.WriteLine("Level 6 Elapsed Time: " + elapsedMs); | |
watch = System.Diagnostics.Stopwatch.StartNew(); | |
options.CompressionType = OoxmlCompressionType.Level9; | |
workbook.Save(outDir + "LargeSampleFile_level_9_out.xlsb", options); | |
watch.Stop(); | |
elapsedMs = watch.ElapsedMilliseconds; | |
Console.WriteLine("Level 9 Elapsed Time: " + elapsedMs); |