تجنب الصفحة الفارغة في ملف PDF الناتج عندما لا يوجد شيء للطباعة
سيناريوهات الاستخدام المحتملة
عندما يكون ملف Excel فارغًا ويقوم المستخدم بحفظه إلى PDF باستخدام Aspose.Cells for Python via .NET، يقوم بتقديم صفحة فارغة في ملف PDF الناتج. في بعض الأحيان، يعتبر هذا السلوك الافتراضي غير مرغوب فيه. توفر Aspose.Cells for Python via .NET خاصية PdfSaveOptions.output_blank_page_when_nothing_to_print للتعامل مع هذه المشكلة. إذا كنت ستضبطها كfalse، فستحدث CellsException كلما لم يكن هناك شيء للطباعة في ملف PDF الناتج.
تجنب الصفحة الفارغة في ملف PDF الناتج عندما لا يوجد شيء للطباعة
يقوم الكود المثالي التالي بإنشاء دفتر عمل فارغ ثم يحفظه كملف PDF بعد تعيين الخاصية PdfSaveOptions.output_blank_page_when_nothing_to_print على false. نظرًا لعدم وجود شيء للطباعة في PDF الناتج ، يحدث CellsException كما هو موضح أدناه.
الكود المثالي
from aspose.cells import PdfSaveOptions, Workbook | |
from io import BytesIO | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create empty workbook. | |
wb = Workbook() | |
# Create Pdf save options. | |
opts = PdfSaveOptions() | |
# Default value of OutputBlankPageWhenNothingToPrint is true. | |
# Setting false means - Do not output blank page when there is nothing to print. | |
opts.output_blank_page_when_nothing_to_print = False | |
# Save workbook to Pdf format, it will throw exception because workbook has nothing to print. | |
ms = BytesIO() | |
try: | |
# Save to Pdf format. It will throw exception. | |
wb.save(ms, opts) | |
except Exception as ex: | |
print(str(ex)) |
استثناء
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)