Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created August 24, 2022 15:12
Show Gist options
  • Save conholdate-gists/11c536a5cad7ca88273a78453fb49caf to your computer and use it in GitHub Desktop.
Save conholdate-gists/11c536a5cad7ca88273a78453fb49caf to your computer and use it in GitHub Desktop.
Convert Excel to PNG in Node.js
// Excel to PNG in Nodejs
var aspose = aspose || {};
aspose.cells = require("aspose.cells");
// Create a workbook object and load the source file
var workbook = new aspose.cells.Workbook("sample.xlsx");
// Instantiate an instance of the ImageOrPrintOptions class to access additional image creation options
var imgOptions = new aspose.cells.ImageOrPrintOptions();
// Set the image type by calling setImageType method
imgOptions.setImageType(aspose.cells.ImageType.PNG);
// Invoke the get(index) method to get the first worksheet.
var sheet = workbook.getWorksheets().get(0);
// Create a SheetRender object for the target sheet
var sr = new aspose.cells.SheetRender(sheet, imgOptions);
for (var j = 0; j < sr.getPageCount(); j++) {
// Invoke the toImage method to generate an image for the worksheet
sr.toImage(j, "WToImage-out" + j + ".png");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment