Évitez les pages vierges dans la sortie PDF lorsqu'il n'y a rien à imprimer
Contents
[
Hide
]
Scénarios d’utilisation possibles
Lorsque le fichier Excel est vide et que l’utilisateur l’enregistre dans PDF à l’aide de Aspose.Cells, il affiche une page vierge dans la sortie PDF. Parfois, ce comportement par défaut n’est pas souhaitable. Aspose.Cells fournit lePdfSaveOptions.OutputBlankPageWhenNothingToPrint propriété pour régler ce problème. Si vous le définissez commefaux, ensuiteCellsExceptionse produira chaque fois qu’il n’y a rien à imprimer dans la sortie PDF.
Évitez les pages vierges dans la sortie PDF lorsqu’il n’y a rien à imprimer
L’exemple de code suivant crée un classeur vide, puis l’enregistre sous PDF après avoir défini lePdfSaveOptions.OutputBlankPageWhenNothingToPrint propriété commefaux. Puisqu’il n’y a rien à imprimer dans la sortie PDF, leCellsExceptionse produit comme indiqué ci-dessous.
Exemple de code
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 | |
//Create empty workbook. | |
Workbook wb = new Workbook(); | |
//Create Pdf save options. | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
//Default value of OutputBlankPageWhenNothingToPrint is true. | |
//Setting false means - Do not output blank page when there is nothing to print. | |
opts.OutputBlankPageWhenNothingToPrint = false; | |
//Save workbook to Pdf format, it will throw exception because workbook has nothing to print. | |
MemoryStream ms = new MemoryStream(); | |
try | |
{ | |
//Save to Pdf format. It will throw exception. | |
wb.Save(ms, opts); | |
} | |
catch (Exception ex) | |
{ | |
Console.Write("Exception Message: " + ex.Message + "\r\n"); | |
} |
Exception
Aspose.Cells.CellsException was unhandled
HResult=-2146232832
Message=There is nothing to output/print.
Source=Aspose.Cells
StackTrace:
at Aspose.Cells.Workbook.Save(String fileName, SaveOptions saveOptions)