マージンの設定
マージンの設定
Aspose.CellsにはExcelファイルを表すWorkbookというクラスがあります。WorkbookクラスにはWorksheetsコレクションが含まれており、Excelファイルの各ワークシートにアクセスできます。ワークシートはWorksheetクラスで表されます。
Worksheetクラスはワークシートのページ設定オプションを設定するために使用されるPageSetupプロパティを提供します。PageSetup属性は、印刷されたワークシートの異なるページレイアウトオプションを設定するためのPageSetupクラスのオブジェクトです。PageSetupクラスには、ページ設定オプションを設定するために使用されるさまざまなプロパティやメソッドが提供されています。
ページ余白
ページの余白(左、右、上、下)をPageSetupクラスのメンバーを使用して設定します。以下にいくつかのメソッドをリストします。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object | |
Workbook workbook = new Workbook(); | |
// Get the worksheets in the workbook | |
WorksheetCollection worksheets = workbook.Worksheets; | |
// Get the first (default) worksheet | |
Worksheet worksheet = worksheets[0]; | |
// Get the pagesetup object | |
PageSetup pageSetup = worksheet.PageSetup; | |
// Set bottom,left,right and top page margins | |
pageSetup.BottomMargin = 2; | |
pageSetup.LeftMargin = 1; | |
pageSetup.RightMargin = 1; | |
pageSetup.TopMargin = 3; | |
// Save the Workbook. | |
workbook.Save(dataDir + "SetMargins_out.xls"); |
ページの中央に配置
ページ上で何かを水平および垂直に中央揃えすることが可能です。これには、PageSetup クラスの有用なメンバー、CenterHorizontally および CenterVertically があります。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook object | |
Workbook workbook = new Workbook(); | |
// Get the worksheets in the workbook | |
WorksheetCollection worksheets = workbook.Worksheets; | |
// Get the first (default) worksheet | |
Worksheet worksheet = worksheets[0]; | |
// Get the pagesetup object | |
PageSetup pageSetup = worksheet.PageSetup; | |
// Specify Center on page Horizontally and Vertically | |
pageSetup.CenterHorizontally = true; | |
pageSetup.CenterVertically = true; | |
// Save the Workbook. | |
workbook.Save(dataDir + "CenterOnPage_out.xls"); |
ヘッダーとフッタのマージン
PageSetup クラスのメンバーでヘッダーとフッターの余白を設定するには、HeaderMargin や FooterMargin などを使用します。