Monitora il progresso della conversione di Excel in TIFF

Possibili Scenari di Utilizzo

A volte la conversione di file di Excel di grandi dimensioni può richiedere del tempo. Durante questo periodo, potresti voler mostrare il progresso della conversione del documento invece di solo una schermata di caricamento per migliorare l’utilizzabilità della tua applicazione. Aspose.Cells supporta il monitoraggio del processo di conversione dei documenti fornendo l’interfaccia IPageSavingCallback. L’interfaccia IPageSavingCallback fornisce i metodi PageStartSaving e PageEndSaving che è possibile implementare nella tua classe personalizzata. È inoltre possibile controllare quali pagine vengono renderizzate come dimostrato nella classe personalizzata TestPageSavingCallback.

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 sua conversione nella console utilizzando la classe personalizzata TestPageSavingCallback che implementa l’interfaccia IPageSavingCallback. Il file di output generato è allegato per il tuo riferimento.

Output File

Codice di Esempio

// 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");

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-.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;
}
}
}

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</br>