Evitare Pagina Vuota nel PDF di Output quando non c è Nulla da Stampare
Possibili Scenari di Utilizzo
Quando il file Excel è vuoto e l’utente lo salva in PDF utilizzando Aspose.Cells, viene visualizzata una pagina vuota nel PDF di output. A volte, questo comportamento predefinito non è desiderato. Aspose.Cells fornisce la proprietà PdfSaveOptions.OutputBlankPageWhenNothingToPrint per gestire questo problema. Se la si imposta su false, allora si verificherà CellsException quando non c’è nulla da stampare nel PDF di output.
Evitare Pagina Vuota nel PDF di Output quando non c’è Nulla da Stampare
Il codice di esempio seguente crea un foglio di lavoro vuoto e lo salva come PDF dopo aver impostato la proprietà PdfSaveOptions.OutputBlankPageWhenNothingToPrint su false. Poiché non c’è nulla da stampare nel PDF di output, si verifica CellsException come mostrato di seguito.
Codice di Esempio
// 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"); | |
} |
Eccezione
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)