Render Sequence of Pages using PageIndex and PageCount Properties of ImageOrPrintOptions with Node.js via C++

Possible Usage Scenarios

You can render a sequence of pages of your Excel file to images by using Aspose.Cells with ImageOrPrintOptions.getPageIndex() and ImageOrPrintOptions.getPageCount() properties. These properties are useful when there are so many e.g. thousands of pages in your worksheet but you want to render some of them only. This will not only save the processing time but will also save the memory consumption of the rendering process.

Render Sequence of Pages using PageIndex and PageCount Properties of ImageOrPrintOptions

The following sample code loads the sample Excel file and renders only pages 4, 5, 6, and 7 using the ImageOrPrintOptions.getPageIndex() and ImageOrPrintOptions.getPageCount() properties. Here are the rendered pages generated by the code.

todo:image_alt_text todo:image_alt_text
todo:image_alt_text todo:image_alt_text

Sample Code

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

// Source directory
const sourceDir = path.join(__dirname, "data");
// Output directory
const outputDir = path.join(__dirname, "output");
// Load the sample Excel file
const workbook = new AsposeCells.Workbook(path.join(sourceDir, "sampleImageOrPrintOptions_PageIndexPageCount.xlsx"));
// Access the first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Specify image or print options
// We want to print pages 4, 5, 6, 7
const opts = new AsposeCells.ImageOrPrintOptions();
opts.setPageIndex(3);
opts.setPageCount(4);
opts.setImageType(AsposeCells.ImageType.Png);
// Create sheet render object
const sheetRender = new AsposeCells.SheetRender(worksheet, opts);
// Print all the pages as images
for (let i = opts.getPageIndex(); i < sheetRender.getPageCount(); i++) {
sheetRender.toImage(i, path.join(outputDir, `outputImage-${i + 1}.png`));
}