Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Headers and footers are displayed only in Page Layout view, Print Preview, and on printed pages.
You can also use the Page Setup dialog box if you want to view headers or footers for more than one worksheet at a time.
For other sheet types, such as chart sheets, or charts, you can insert headers and footers only by using the Page Setup dialog box.
With PageSetup.getHeader(number) and PageSetup.getFooter(number) methods, Node.js developers can simply get headers or footers from the file.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "HeaderFooter.xlsx");
// Instantiate a new Workbook
const workbook = new AsposeCells.Workbook(filePath);
const sheet = workbook.getWorksheets().get(0);
// Gets left section of header
console.log(sheet.getPageSetup().getHeader(0));
// Gets center section of header
console.log(sheet.getPageSetup().getHeader(1));
// Gets right section of header
console.log(sheet.getPageSetup().getHeader(2));
// Gets center section of footer
console.log(sheet.getPageSetup().getFooter(1));
The header or footer text can contain special commands, for example, a placeholder for the page number, current date, or text formatting attributes.
Special commands are represented by a single letter with a leading ampersand ("&").
The header and footer strings are constructed using ABNF grammar. It’s not easy to understand without a viewer.
Aspose.Cells for Node.js via C++ provides PageSetup.getCommands(string) method to parse headers and footers as a command list.
The following codes show how to parse the header or footer as a command list and process commands:
try {
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "HeaderFooter.xlsx");
// Instantiate a new Workbook.
const workbook = new AsposeCells.Workbook(filePath);
const sheet = workbook.getWorksheets().get(0);
// Gets left section of header
const headerSection = sheet.getPageSetup().getHeader(0);
const commands = sheet.getPageSetup().getCommands(headerSection) || [];
commands.forEach(c => {
switch (c.getType()) {
case AsposeCells.HeaderFooterCommandType.SheetName:
// embedded the name of the sheet to header or footer
break;
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.