Печать диапазона страниц с использованием 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))