//create to 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 to a png file stream var outputStream: FileOutputStream? = null try { outputStream = FileOutputStream("ExportSheetToImage.png") } catch (e: FileNotFoundException) { e.printStackTrace() } //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) //close the file stream try { if(outputStream != null){ outputStream.close() } } catch (e: IOException) { e.printStackTrace() }