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 conversion du document au lieu d’un simple écran de chargement pour améliorer la convivialité 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 démontre la classe personnalisée TestPageSavingCallback.

Suivre la progression de la conversion des documents

L’exemple de code 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-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
Workbook workbook = new Workbook(sourceDir + "PagesBook1.xlsx");
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.PageSavingCallback = new TestPageSavingCallback();
workbook.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-.NET
public class TestPageSavingCallback : 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;
}
}
}

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