تجنب الصفحة الفارغة في الإخراج PDF عندما لا يوجد شيء للطباعة
Contents
[
Hide
]
سيناريوهات الاستخدام الممكنة
عندما يكون ملف Excel فارغًا ويقوم المستخدم بحفظه في PDF باستخدام Aspose.Cells ، فإنه يعرض صفحة فارغة في الإخراج PDF. أحيانًا يكون هذا السلوك الافتراضي غير مرغوب فيه. يوفر Aspose.Cells ملفPdfSaveOptions.OutputBlankPageWhenNothingToPrint خاصية للتعامل مع هذه القضية. إذا قمت بتعيينه على أنهخاطئة، ومن بعدCellsExceptionسيحدث عندما لا يوجد شيء يمكن طباعته في الإخراج PDF.
تجنب الصفحة الفارغة في الإخراج PDF عندما لا يوجد شيء للطباعة
يقوم نموذج التعليمات البرمجية التالي بإنشاء مصنف فارغ ثم يحفظه كـ PDF بعد تعيين ملفPdfSaveOptions.OutputBlankPageWhenNothingToPrint الملكية مثلخاطئة. نظرًا لعدم وجود شيء يمكن طباعته في الإخراج PDF ، فإن ملفCellsExceptionيحدث كما هو موضح أدناه.
عينة من الرموز
This file contains hidden or 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"); | |
} |
استثناء
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)