طباعة نطاق الصفحات باستخدام SheetRender و WorkbookRender

واجهة Microsoft Excel لتحديد نطاق الصفحات المراد طباعتها

الشيفرة التالية توضح استخدام WorkbookRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount) و SheetRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount). إنها تطبع الصفحات 2-5 من الكتاب أو الورقة العمل.

from aspose.cells import Workbook
from aspose.cells.rendering import ImageOrPrintOptions, SheetRender, WorkbookRender
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create workbook from source Excel file
workbook = Workbook(dataDir + "SampleBook.xlsx")
printerName = ""
while null == printerName or "" == printerName:
print("Please Enter Your Printer Name:")
printerName = input()
bookRenderOptions = ImageOrPrintOptions()
bookRenderOptions.page_index = 1
bookRenderOptions.page_count = 2
# Print the worbook specifying the range of pages. Here we are printing pages 2-3
wr = WorkbookRender(workbook, ImageOrPrintOptions())
try:
wr.to_printer(printerName)
except Exception as ex:
print(str(ex))
# Access first worksheet
worksheet = workbook.worksheets[0]
sheetRenderOptions = ImageOrPrintOptions()
sheetRenderOptions.page_index = 1
sheetRenderOptions.page_count = 2
# Print the worksheet specifying the range of pages. Here we are printing pages 2-3
sr = SheetRender(worksheet, ImageOrPrintOptions())
try:
sr.to_printer(printerName)
except Exception as ex:
print(str(ex))