Excel API Library for Java - Sample Browser | Document Solutions | Convert sheet to image from existing file
[
フレーム]
src="bundle.js">
Refer to the following example code to see how to convert a worksheet to an image.
// Create a png file stream
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("ExportSheetToImage.png");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create a new workbook
Workbook workbook = new Workbook();
workbook.open(this.getResourceStream("xlsx/Home inventory.xlsx"));
IWorksheet worksheet = workbook.getWorksheets().get(0);
// Save the worksheet as image to a stream.
worksheet.toImage(outputStream, ImageType.PNG);
// Close the file stream
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
// Create a Image file stream
FileOutputStream("ExportSheetToImage.png").use {
val outputStream = it
// Create a new workbook
var workbook = Workbook()
workbook.open(this.getResourceStream("xlsx/Home inventory.xlsx"))
val worksheet = workbook.worksheets.get(0)
// Save the worksheet as image to a stream.
worksheet.toImage(outputStream, ImageType.PNG)
// End using the file stream
}