印刷オプションの設定
印刷オプションの設定方法
これらの印刷オプションにより、ユーザーは次のような操作を行うことができます:
- ワークシート上の特定の印刷範囲を選択する。
- タイトルを印刷する。
- グリッド線を印刷する。
- 行/列見出しを印刷します。
- 下書き品質を実現する。
- コメントを印刷する。
- セルエラーを印刷する。
- ページ順序を定義する。
Aspose.Cells for Python via .NETは、Microsoft Excelが提供するすべての印刷オプションをサポートしており、PageSetupクラスが提供するプロパティを使用してワークシートのこれらのオプションを簡単に設定できます。これらのプロパティの使用方法については、以下で詳しく説明します。
印刷範囲の設定方法
デフォルトでは、印刷エリアにはデータを含むワークシートのすべての領域が組み込まれます。開発者はワークシートの特定の印刷エリアを設定することができます。
特定の印刷エリアを選択するには、PageSetup クラスの print_area プロパティを使用します。このプロパティに、印刷エリアを定義するセル範囲を割り当てます。
from aspose.cells import Workbook | |
# 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(".") | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the PageSetup of the worksheet | |
pageSetup = workbook.worksheets[0].page_setup | |
# Specifying the cells range (from A1 cell to T35 cell) of the print area | |
pageSetup.print_area = "A1:T35" | |
# Save the workbook. | |
workbook.save(dataDir + "SetPrintArea_out.xls") |
印刷タイトルの設定方法
Aspose.Cells for Python via .NET では、行と列の見出しをすべてのページで繰り返すように指定できます。これを行うには、PageSetup クラスの print_title_columns および print_title_rows プロパティを使用します。
繰り返す行または列は、その行番号または列番号を渡すことで定義されます。たとえば、行は$1:$2と定義され、列は$A:$Bと定義されます。
from aspose.cells import Workbook | |
# 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(".") | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the PageSetup of the worksheet | |
pageSetup = workbook.worksheets[0].page_setup | |
# Defining column numbers A & B as title columns | |
pageSetup.print_title_columns = "$A:$B" | |
# Defining row numbers 1 & 2 as title rows | |
pageSetup.print_title_rows = "$1:$2" | |
# Save the workbook. | |
workbook.save(dataDir + "SetPrintTitle_out.xls") |
他の印刷オプションの設定方法
PageSetup クラスには、以下の一般的な印刷オプションを設定するためのいくつかの他のプロパティも提供されています:
- print_grid_lines: グリッド線を印刷するかどうかを定義するブール型のプロパティ。
- print_headings: 行および列見出しを印刷するかどうかを定義するブール型のプロパティ。
- black_and_white: ブラックアンドホワイトモードでワークシートを印刷するかどうかを定義するブールプロパティ。
- print_comments: ワークシート上に印刷コメントを表示するか、ワークシートの最後に表示するかを定義する。
- print_draft: グラフィックを排除してシートを印刷するかどうかを定義するブールプロパティ。
- print_errors: 表示されるままのセルエラー、空白、ダッシュ、またはN/A として印刷するかを定義する。
Aspose.Cellsは、print_comments と print_errors プロパティを設定するために、PrintCommentsType と PrintErrorsType という2つの列挙型を提供しています。これらの列挙型には、それぞれ print_comments と print_errors プロパティに割り当てるための事前に定義された値が含まれています。
PrintCommentsType 列挙型の事前に定義された値は、以下にその説明とともにリストされています。
コメント印刷タイプ | 説明 |
---|---|
PRINT_IN_PLACE | コメントをワークシートに表示されている通りに印刷します。 |
PRINT_NO_COMMENTS | コメントを印刷しません。 |
PRINT_SHEET_END | コメントをワークシートの最後に印刷します。 |
PrintErrorsType 列挙型の事前に定義された値は、以下にその説明とともにリストされています。
エラー印刷タイプ | 説明 |
---|---|
PRINT_ERRORS_BLANK | エラーを印刷しません。 |
PRINT_ERRORS_DASH | エラーを “–” として印刷します。 |
PRINT_ERRORS_DISPLAYED | 表示されたエラーをそのまま印刷します。 |
PRINT_ERRORS_NA | エラーを “#N/A” として印刷します。 |
from aspose.cells import PrintCommentsType, PrintErrorsType, Workbook | |
# 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(".") | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the PageSetup of the worksheet | |
pageSetup = workbook.worksheets[0].page_setup | |
# Allowing to print gridlines | |
pageSetup.print_gridlines = True | |
# Allowing to print row/column headings | |
pageSetup.print_headings = True | |
# Allowing to print worksheet in black & white mode | |
pageSetup.black_and_white = True | |
# Allowing to print comments as displayed on worksheet | |
pageSetup.print_comments = PrintCommentsType.PRINT_IN_PLACE | |
# Allowing to print worksheet with draft quality | |
pageSetup.print_draft = True | |
# Allowing to print cell errors as N/A | |
pageSetup.print_errors = PrintErrorsType.PRINT_ERRORS_NA | |
# Save the workbook. | |
workbook.save(dataDir + "OtherPrintOptions_out.xls") |
ページ順を設定する方法
PageSetup クラスは、ワークシートを印刷するための複数のページの順序を設定するために使用される Order プロパティを提供します。ページを順に印刷するためには、次の2つの可能性があります。
- Down then over: 右側のページを印刷する前に、すべてのページを下に印刷します。
- Over then down: 下側のページを印刷する前に、左から右のページを印刷します。
Aspose.Cellsは、PrintOrderType という列挙型を提供し、すべての事前に定義された順序タイプが含まれています。
列挙型 PrintOrderType の事前に定義された値は、以下にその説明とともにリストされています。
印刷順序タイプ | 説明 |
---|---|
DOWN_THEN_OVER | 行きから列へ印刷の順序を表します。 |
OVER_THEN_DOWN | 列から行へ印刷の順序を表します。 |
from aspose.cells import PrintOrderType, Workbook | |
# 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(".") | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Obtaining the reference of the PageSetup of the worksheet | |
pageSetup = workbook.worksheets[0].page_setup | |
# Setting the printing order of the pages to over then down | |
pageSetup.order = PrintOrderType.OVER_THEN_DOWN | |
# Save the workbook. | |
workbook.save(dataDir + "SetPageOrder_out.xls") |