Node.js経由のC++を使用したマージン設定

マージンの設定

Aspose.Cellsは、Excelファイルを表す Workbookクラスを提供します。 Workbookクラスは、Excelファイル内の各ワークシートへアクセス可能な Workbook.getWorksheets()コレクションを含みます。ワークシートは Worksheetクラスで表されます。

Worksheetクラスは、ワークシートのページセットアップオプションを設定するために使用される Worksheet.getPageSetup()プロパティを提供します。Worksheet.getPageSetup()属性はWorksheet.getPageSetup()クラスのオブジェクトであり、印刷されたワークシートのページレイアウト設定を可能にします。Worksheet.getPageSetup()クラスはさまざまなページ設定オプションを設定するためのプロパティとメソッドを提供します。

ページ余白

ページ余白(左、右、上、下)をWorksheet.getPageSetup()クラスのメンバーを使って設定します。一部のメソッド例は以下の通りです。

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Create a workbook object
const workbook = new AsposeCells.Workbook();

// Get the worksheets in the workbook
const worksheets = workbook.getWorksheets();

// Get the first (default) worksheet
const worksheet = worksheets.get(0);

// Get the pagesetup object
const pageSetup = worksheet.getPageSetup();

// Set bottom, left, right and top page margins
pageSetup.setBottomMargin(2);
pageSetup.setLeftMargin(1);
pageSetup.setRightMargin(1);
pageSetup.setTopMargin(3);

// Save the Workbook.
workbook.save(path.join(dataDir, "SetMargins_out.xls"));

ページの中央に配置

ページを横方向および縦方向に中央揃えに配置することは可能です。そのための便利なメンバーとしてWorksheet.getPageSetup()クラスのPageSetup.getCenterHorizontally()PageSetup.getCenterVertically()があります。

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Create a workbook object
const workbook = new AsposeCells.Workbook();

// Get the worksheets in the workbook
const worksheets = workbook.getWorksheets();

// Get the first (default) worksheet
const worksheet = worksheets.get(0);

// Get the pagesetup object
const pageSetup = worksheet.getPageSetup();

// Specify Center on page Horizontally and Vertically
pageSetup.setCenterHorizontally(true);
pageSetup.setCenterVertically(true);

// Save the Workbook.
workbook.save(path.join(dataDir, "CenterOnPage_out.xls"));

ヘッダーとフッタのマージン

ヘッダーとフッターの余白を設定するには、Worksheet.getPageSetup()クラスのメンバーであるPageSetup.getHeaderMargin()PageSetup.getFooterMargin()を使います。

const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");

// Create a workbook object
const workbook = new AsposeCells.Workbook();

// Get the worksheets in the workbook
const worksheets = workbook.getWorksheets();

// Get the first (default) worksheet
const worksheet = worksheets.get(0);

// Get the pagesetup object
const pageSetup = worksheet.getPageSetup();

// Specify Header / Footer margins
pageSetup.setHeaderMargin(2);
pageSetup.setFooterMargin(2);

// Save the Workbook.
workbook.save(path.join(dataDir, "CenterOnPage_out.xls"));