Created
December 17, 2022 16:58
Extract Images From Excel in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var aspose = aspose || {}; | |
aspose.cells = require("aspose.cells"); | |
// Create a workbook object from the source file. | |
var workbook = new aspose.cells.Workbook("sample.xlsx"); | |
// Get the first worksheet by calling the get method. | |
var worksheet = workbook.getWorksheets().get(0); | |
// Invoke the get method to get the first Picture in the first worksheet. | |
var pic = worksheet.getPictures().get(0); | |
// Set the output image file path. | |
var fileName = "aspose-logo.jpg"; | |
// Instantiate an instance of the ImageOrPrintOptions class. | |
var printoption = new aspose.cells.ImageOrPrintOptions(); | |
// Specify the image format to JPEG or PNG. | |
printoption.setImageType(aspose.cells.ImageType.JPEG); | |
// Save the image by calling the toImage method. | |
pic.toImage(fileName, printoption); |
You may use Aspose.Cells for Node.js via Java API for the task. Please see the following code segment for your reference.
var fs = require('fs');
var aspose = aspose || {};
aspose.cells = require("aspose.cells.java");
// Create a workbook object from the source file.
var workbook = new aspose.cells.Workbook("YourExcelFile.xlsx");
// Get the worksheet by calling the get method with its (sheet) name.
var worksheet = workbook.getWorksheets().get("sheet2");
// Invoke the get method to get the first Picture in the first worksheet.
var pic = worksheet.getPictures().get(0);
// Set the output image file path.
var fileName = "image1.jpg";
// Instantiate an instance of the ImageOrPrintOptions class.
var printoption = new aspose.cells.ImageOrPrintOptions();
// Specify the image format to JPEG or PNG.
printoption.setImageType(aspose.cells.ImageType.JPEG);
// Save the image by calling the toImage method.
pic.toImage(fileName, printoption);
Hope, this helps a bit.
You may also post your queries in the dedicated forum.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to get image in sheet2 from excel using node js using xlxs lib