Created
March 10, 2021 17:19
-
-
Save aspose-com-gists/634e9fb6f8515504317a7b71aa57b17a to your computer and use it in GitHub Desktop.
Excel to Image Conversion Java
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
// Load Excel file | |
Workbook workbook = new Workbook("workbook.xlsx"); | |
// Create an object of ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the image type | |
imgOptions.setImageType(ImageType.PNG); | |
// Set one page per sheet rendering | |
imgOptions.setOnePagePerSheet(true); | |
// Set gridline | |
imgOptions.setGridlineType(GridlineType.DOTTED); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Create a SheetRender object for the target sheet | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int page = 0; page < sr.getPageCount(); page++) { | |
// Generate an image for the worksheet | |
sr.toImage(page, "image" + page + ".png"); | |
} |
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
// Load Excel file | |
Workbook workbook = new Workbook("workbook.xlsx"); | |
// Create an object of ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the output image type | |
imgOptions.setImageType(ImageType.PNG); | |
// Get the first worksheet | |
Worksheet sheet = workbook.getWorksheets().get(0); | |
// Create a SheetRender object for the target sheet | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
for (int page = 0; page < sr.getPageCount(); page++) { | |
// Generate an image for the worksheet | |
sr.toImage(page, "image" + page + ".png"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment