Impostare margini con Node.js tramite C++

Impostazione margini

Aspose.Cells fornisce una classe, Workbook, che rappresenta un file Excel. La classe Workbook contiene la collezione Workbook.getWorksheets() che consente l’accesso a ogni foglio di lavoro del file Excel. Un foglio di lavoro viene rappresentato dalla classe Worksheet.

La classe Worksheet fornisce la proprietà Worksheet.getPageSetup() usata per impostare le opzioni di configurazione della pagina per un foglio di lavoro. L’attributo Worksheet.getPageSetup() è un oggetto della classe Worksheet.getPageSetup() che permette agli sviluppatori di impostare diverse opzioni di layout di pagina per un foglio di lavoro stampato. La classe Worksheet.getPageSetup() fornisce varie proprietà e metodi usati per impostare le opzioni di configurazione della pagina.

Margini di Pagina

Imposta margini di pagina (sinistra, destra, superiore, inferiore) utilizzando membri della classe Worksheet.getPageSetup(). Alcuni dei metodi sono elencati di seguito e vengono usati per specificare i margini di pagina:

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"));

Centra sulla Pagina

È possibile centrare qualcosa su una pagina orizzontalmente e verticalmente. Per questo, ci sono alcuni membri utili della classe Worksheet.getPageSetup(), PageSetup.getCenterHorizontally() e 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"));

Margini Intestazione e Piè di Pagina

Imposta i margini di intestazione e piè di pagina con membri della classe Worksheet.getPageSetup() come PageSetup.getHeaderMargin() e 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"));