SheetRenderとWorkbookRenderを使用してページの印刷範囲を印刷する
Microsoft Excelでは、ブックまたはワークシートのページの範囲を印刷できます。次のスクリーンショットは、ページの範囲を指定するMicrosoft Excelのインターフェースを示しています。
Aspose.Cells for Python via .NETは、この目的のためにWorkbookRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount)とSheetRender.ToPrinter(string PrinterName, int PrintPageIndex, int PrintPageCount)メソッドを提供します。
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)) |