Boş sayfa olmadığında Çıktı PDF de Boş Sayfa İşlemi
Olası Kullanım Senaryoları
Excel dosyası boş olduğunda ve kullanıcı Aspose.Cells’i kullanarak PDF’ye kaydettiğinde, çıktı PDF’de boş bir sayfa oluşturur. Bu varsayılan davranış bazen istenmeyebilir. Aspose.Cells, bu sorunla başa çıkmak için PdfSaveOptions.OutputBlankPageWhenNothingToPrint özelliğini sağlar. Eğer bu özelliği false olarak ayarlarsanız, çıktı PDF’de bir şey basılacak olmadığında CellsException meydana gelecektir.
Çıktı PDF’inde Boş Sayfa Oluşmasını Engelle
Aşağıdaki örnek kod, boş bir çalışma kitabı oluşturur ve ardından false olarak ayarlanmış olan PdfSaveOptions.OutputBlankPageWhenNothingToPrint özelliğini ayarladıktan sonra PDF olarak kaydeder. Çıktı PDF’de yazdırılacak bir şey olmadığı için aşağıdaki gibi CellsException gösterilir.
Örnek Kod
// 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"); | |
} |
İstisna
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)