跟踪 Excel 到 TIFF 的转换进度
Contents
[
Hide
]
可能的使用场景
有时转换大型 Excel 文件可能需要一些时间。在此期间,您可能希望显示文档转换进度而不仅仅是加载屏幕,以增强应用程序的可用性。 Aspose.Cells 通过提供支持跟踪文档转换过程**IPageSavingCallback**界面。这**IPageSavingCallback**接口提供**PageStartSaving**和**PageEndSaving**您可以在自定义类中实现的方法。您还可以控制呈现哪些页面,如 T 中所示*estPageSavingCallback*自定义类。
跟踪 Excel 到 TIFF 的转换进度
以下代码示例加载源文件并使用测试页面保存回调实现的自定义类**IPageSavingCallback**界面。附上生成的输出文件供您参考。
示例代码
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(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx"); | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.PageSavingCallback = new TestTiffPageSavingCallback(); | |
opts.ImageType = ImageType.Tiff; | |
WorkbookRender wr = new WorkbookRender(workbook, opts); | |
wr.ToImage(outputDir + "DocumentConversionProgressForTiff_out.tiff"); |
以下是代码测试 TiffPageSavingCallback自定义类。
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 | |
public class TestTiffPageSavingCallback : IPageSavingCallback | |
{ | |
public void PageStartSaving(PageStartSavingArgs args) | |
{ | |
Console.WriteLine("Start saving page index {0} of pages {1}", args.PageIndex, args.PageCount); | |
//don't output pages before page index 2. | |
if (args.PageIndex < 2) | |
{ | |
args.IsToOutput = false; | |
} | |
} | |
public void PageEndSaving(PageEndSavingArgs args) | |
{ | |
Console.WriteLine("End saving page index {0} of pages {1}", args.PageIndex, args.PageCount); | |
//don't output pages after page index 8. | |
if (args.PageIndex >= 8) | |
{ | |
args.HasMorePages = false; | |
} | |
} | |
} |
控制台输出
开始保存第 10 页的第 0 页索引
结束保存页面索引 0 of pages 10
开始保存第 10 页的第 1 页索引
结束保存页面索引 1 of pages 10
开始保存第 10 页的第 2 页索引
结束保存第 10 页的第 2 页索引
开始保存第 10 页的第 3 页索引
结束保存第 10 页的第 3 页索引
开始保存第 10 页的第 4 页索引
结束保存页面索引 4 of pages 10
开始保存第 10 页的第 5 页索引
结束保存第 10 页的第 5 页索引
开始保存第 10 页的第 6 页索引
结束保存页面索引 6 of pages 10
开始保存第 10 页的第 7 页索引
结束保存页面索引 7 of pages 10
开始保存第 10 页的第 8 页索引
结束保存页面索引 8,共 10 页