Generar miniatura de la hoja de trabajo con Node.js vía C++
Contents
[
Hide
]
Puede ser útil generar miniaturas de hojas de cálculo. Una miniatura es una imagen pequeña que se puede pegar en un documento de Word o en una presentación de PowerPoint para dar una vista previa de lo que hay en la hoja de cálculo. Se puede agregar a una página web con un enlace para descargar el documento original y tiene una serie de otros usos.
Aspose.Cells for Node.js via C++ le permite exportar hojas de trabajo a archivos de imagen, por lo que crear una miniatura es fácil. El código de ejemplo a continuación muestra cómo exportar hojas de trabajo a archivos de imagen.
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");
// Instantiate and open an Excel file
const filePath = path.join(sourceDir, "sampleGenerateThumbnailOfWorksheet.xlsx");
const book = new AsposeCells.Workbook(filePath);
// Define ImageOrPrintOptions
const imgOptions = new AsposeCells.ImageOrPrintOptions();
// Specify the image format
imgOptions.setImageType(AsposeCells.ImageType.Jpeg);
// Set the vertical and horizontal resolution
imgOptions.setVerticalResolution(200);
imgOptions.setHorizontalResolution(200);
// One page per sheet is enabled
imgOptions.setOnePagePerSheet(true);
// Set desired thumbnail dimensions
imgOptions.setDesiredSize(600, 600, true);
// Get the first worksheet
const sheet = book.getWorksheets().get(0);
// Render the sheet with respect to specified image/print options
const sr = new AsposeCells.SheetRender(sheet, imgOptions);
// Save the thumbnail directly
sr.toImage(0, path.join(outputDir, "outputGenerateThumbnailOfWorksheet.jpg"));