マージンの設定
余白の設定方法
Aspose.Cells for Python via .NET は、Excelファイルを表すクラス Workbook を提供します。Workbook クラスは、Excelファイル内の各ワークシートにアクセスできる worksheets コレクションを含みます。ワークシートは Worksheet クラスで表されます。
Worksheetクラスはワークシートのページ設定オプションを設定するために使用されるpage_setupプロパティを提供します。page_setup属性は、印刷されたワークシートの異なるページレイアウトオプションを設定するためのPageSetupクラスのオブジェクトです。PageSetupクラスには、ページ設定オプションを設定するために使用されるさまざまなプロパティやメソッドが提供されています。
ページ余白の設定方法
ページの余白(左、右、上、下)をPageSetupクラスのメンバーを使用して設定します。以下にいくつかのメソッドをリストします。
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(".") | |
# Create a workbook object | |
workbook = Workbook() | |
# Get the worksheets in the workbook | |
worksheets = workbook.worksheets | |
# Get the first (default) worksheet | |
worksheet = worksheets[0] | |
# Get the pagesetup object | |
pageSetup = worksheet.page_setup | |
# Set bottom,left,right and top page margins | |
pageSetup.bottom_margin = 2.0 | |
pageSetup.left_margin = 1.0 | |
pageSetup.right_margin = 1.0 | |
pageSetup.top_margin = 3.0 | |
# Save the Workbook. | |
workbook.save(dataDir + "SetMargins_out.xls") |
ページ上で中央揃えにする方法
ページ上で何かを水平および垂直に中央揃えすることが可能です。これには、PageSetup クラスの有用なメンバー、center_horizontally および center_vertically があります。
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(".") | |
# Create a workbook object | |
workbook = Workbook() | |
# Get the worksheets in the workbook | |
worksheets = workbook.worksheets | |
# Get the first (default) worksheet | |
worksheet = worksheets[0] | |
# Get the pagesetup object | |
pageSetup = worksheet.page_setup | |
# Specify Center on page Horizontally and Vertically | |
pageSetup.center_horizontally = True | |
pageSetup.center_vertically = True | |
# Save the Workbook. | |
workbook.save(dataDir + "CenterOnPage_out.xls") |
ヘッダーとフッターの余白を設定する方法
PageSetup クラスのメンバーでヘッダーとフッターの余白を設定するには、header_margin や footer_margin などを使用します。