Monitora il progresso della conversione di Excel in TIFF
Possibili Scenari di Utilizzo
A volte la conversione di grandi file Excel può richiedere del tempo. Durante questo periodo, potresti voler mostrare il progresso della conversione del documento anziché solo una schermata di caricamento per migliorare l’usabilità della tua applicazione. Aspose.Cells supporta il tracciamento del processo di conversione del documento fornendo l’interfaccia IPageSavingCallback. L’interfaccia IPageSavingCallback fornisce i metodi PageStartSaving e PageEndSaving che puoi implementare nella tua classe personalizzata. Puoi anche controllare quali pagine vengono renderizzate come dimostrato nella classe personalizzata TestTiffPageSavingCallback.
Monitora il progresso della conversione di Excel in TIFF
Il seguente esempio di codice carica il file Excel di origine e stampa il progresso della conversione nella console utilizzando la classe personalizzata TestTiffPageSavingCallback che implementa l’interfaccia IPageSavingCallback. Il file di output generato è allegato per il tuo riferimento.
Codice di Esempio
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the source directory. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
// The path to the output directory. | |
String outputDir = Utils.Get_OutputDirectory(); | |
Workbook wb = new Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx"); | |
ImageOrPrintOptions opts = new ImageOrPrintOptions(); | |
opts.setPageSavingCallback(new TestTiffPageSavingCallback()); | |
opts.setImageType(ImageType.TIFF); | |
WorkbookRender wr = new WorkbookRender(wb, opts); | |
wr.toImage(outputDir + "DocumentConversionProgressForTiff_out.tiff"); |
Di seguito è riportato il codice per la classe personalizzata TestTiffPageSavingCallback.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
class TestTiffPageSavingCallback implements IPageSavingCallback { | |
public void pageStartSaving(PageStartSavingArgs args) | |
{ | |
System.out.println("Start saving page index " + args.getPageIndex() + " of pages " + args.getPageCount()); | |
//don't output pages before page index 2. | |
if (args.getPageIndex() < 2) | |
{ | |
args.setToOutput(false); | |
} | |
} | |
public void pageEndSaving(PageEndSavingArgs args) | |
{ | |
System.out.println("End saving page index " + args.getPageIndex() + " of pages " + args.getPageCount()); | |
//don't output pages after page index 8. | |
if (args.getPageIndex() >= 8) | |
{ | |
args.setHasMorePages(false); | |
} | |
} | |
} |
Output della console
Start saving page index 0 of pages 10</br>
End saving page index 0 of pages 10</br>
Start saving page index 1 of pages 10</br>
End saving page index 1 of pages 10</br>
Start saving page index 2 of pages 10</br>
End saving page index 2 of pages 10</br>
Start saving page index 3 of pages 10</br>
End saving page index 3 of pages 10</br>
Start saving page index 4 of pages 10</br>
End saving page index 4 of pages 10</br>
Start saving page index 5 of pages 10</br>
End saving page index 5 of pages 10</br>
Start saving page index 6 of pages 10</br>
End saving page index 6 of pages 10</br>
Start saving page index 7 of pages 10</br>
End saving page index 7 of pages 10</br>
Start saving page index 8 of pages 10</br>
End saving page index 8 of pages 10