Preview workbook with Node.js via C++
Print Preview
There may be cases where Excel files with millions of pages need to be converted to PDF or images. Processing such files will consume a lot of time and resources. In such cases, the Workbook and Worksheet Print Preview feature might prove to be useful. Before converting such files, the user can check the total number of pages and then decide whether the file is to be converted or not. This article focuses on using the WorkbookPrintingPreview and SheetPrintingPreview classes to find out the total number of pages.
Aspose.Cells provides the print preview feature. For this, the API provides WorkbookPrintingPreview and SheetPrintingPreview classes. To create the print preview of the whole workbook, create an instance of the WorkbookPrintingPreview class by passing Workbook and ImageOrPrintOptions objects to the constructor. The WorkbookPrintingPreview class provides an getEvaluatedPageCount method which returns the number of pages in the generated preview. Similar to WorkbookPrintingPreview class, the SheetPrintingPreview class is used to generate a print preview for a specific worksheet. To create the print preview of a worksheet, create an instance of the SheetPrintingPreview class by passing Worksheet and ImageOrPrintOptions objects to the constructor. The SheetPrintingPreview class also provides an getEvaluatedPageCount method which returns the number of pages in the generated preview.
The following code snippet demonstrates the use of both WorkbookPrintingPreview and SheetPrintingPreview classes by using the sample excel file.
Sample Code
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Source directory
const sourceDir = path.join(__dirname, "data");
const filePath = path.join(sourceDir, "Book1.xlsx");
const workbook = new AsposeCells.Workbook(filePath);
const imgOptions = new AsposeCells.ImageOrPrintOptions();
const preview = new AsposeCells.WorkbookPrintingPreview(workbook, imgOptions);
console.log("Workbook page count: " + preview.getEvaluatedPageCount());
const preview2 = new AsposeCells.SheetPrintingPreview(workbook.getWorksheets().get(0), imgOptions);
console.log("Worksheet page count: " + preview2.getEvaluatedPageCount());
The following is the output generated by executing the above code.
Console Output
Workbook page count: 1
Worksheet page count: 1
Advance topics
- Configuring Fonts for Rendering Spreadsheets
- Convert Worksheet to Image - Remove whitespace around data
- Converting Worksheet to Image and Worksheet to Image by Page
- Converting Worksheet to Image using ImageOrPrint Options
- Export Range of Cells in a Worksheet to Image
- Export Worksheet or Chart into Image with Desired Width and Height
- Extract Images from Worksheets using ImageOrPrintOptions
- Generate Thumbnail of the Worksheet
- Output Blank Page when there is Nothing to Print
- Page Setup and Printing Options
- Render Sequence of Pages using PageIndex and PageCount Properties of ImageOrPrintOptions
- Render Worksheet to Graphic Context
- Specify Individual or Private Set of Fonts for Workbook Rendering