Suivre l avancement de la conversion du document
Scénarios d’utilisation possibles
Parfois, la conversion de grands fichiers Excel peut prendre du temps. Pendant ce temps, vous voudrez peut-être afficher la progression de la conversion du document plutôt qu’un simple écran de chargement pour améliorer l’utilisabilité de votre application. Aspose.Cells prend en charge le suivi du processus de conversion de document en fournissant l’interface IPageSavingCallback. L’interface IPageSavingCallback fournit les méthodes PageStartSaving et PageEndSaving que vous pouvez implémenter dans votre classe personnalisée. Vous pouvez également contrôler quelles pages sont rendues comme le montre la classe personnalisée TestPageSavingCallback.
Suivre la progression de la conversion des documents
Le code d’exemple suivant charge le fichier Excel source et affiche sa progression de conversion dans la console en utilisant la classe personnalisée TestPageSavingCallback qui implémente l’interface IPageSavingCallback.
Code d’exemple
// 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 + "PagesBook1.xlsx"); | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setPageSavingCallback(new TestPageSavingCallback()); | |
wb.save(outputDir + "DocumentConversionProgress.pdf", pdfSaveOptions); |
Ce qui suit est le code de la classe personnalisée TestPageSavingCallback.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
class TestPageSavingCallback 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); | |
} | |
} | |
} |
Sortie console
Start saving page index 0 of pages 11</br>
End saving page index 0 of pages 11</br>
Start saving page index 1 of pages 11</br>
End saving page index 1 of pages 11</br>
Start saving page index 2 of pages 11</br>
End saving page index 2 of pages 11</br>
Start saving page index 3 of pages 11</br>
End saving page index 3 of pages 11</br>
Start saving page index 4 of pages 11</br>
End saving page index 4 of pages 11</br>
Start saving page index 5 of pages 11</br>
End saving page index 5 of pages 11</br>
Start saving page index 6 of pages 11</br>
End saving page index 6 of pages 11</br>
Start saving page index 7 of pages 11</br>
End saving page index 7 of pages 11</br>
Start saving page index 8 of pages 11</br>
End saving page index 8 of pages 11