使用 C++ 通过 Node.js 设置边距
Contents
[
Hide
]
Aspose.Cells 完全支持微软 Excel 的页面设置选项。开发人员可能需要为工作表配置页面设置以控制打印过程。本主题讨论如何使用 Aspose.Cells 配置页面边距。
设置页边距
Aspose.Cells 提供一个Workbook类,它代表一个Excel文件。 Workbook类包含Workbook.getWorksheets()集合,可以访问Excel文件中的每个工作表。一个工作表由Worksheet类表示。
Worksheet类提供用于设置工作表页面设置选项的Worksheet.getPageSetup()属性。Worksheet.getPageSetup()属性是Worksheet.getPageSetup()类的对象,允许开发者为打印的工作表设置不同的页面布局选项。Worksheet.getPageSetup()类提供各种属性和方法,用于设置页面布局。
页面边距
使用Worksheet.getPageSetup()类成员设置页面边距(左、右、上、下)。以下列出一些用于指定页面边距的方法:
- PageSetup.getLeftMargin()
- PageSetup.getRightMargin()
- PageSetup.getTopMargin()
- PageSetup.getBottomMargin()
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"));