// Create a png file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("ExportChartToImage.png"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); InputStream fileStream = getResourceStream("xlsx/Template_SalesTracker_report.xlsx"); // Open a xlsx file contains a chart workbook.open(fileStream); IWorksheet worksheet = workbook.getWorksheets().get(0); // Export the chart to image worksheet.getShapes().get("ProductIncomeChart").toImage(outputStream, ImageType.PNG); // Close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
// Create a Image file stream FileOutputStream("ExportChartToImage.png").use { val outputStream = it // Create a new workbook var workbook = Workbook() val fileStream = getResourceStream("xlsx\\Template_SalesTracker_report.xlsx") //Open a xlsx file contains a chart workbook.open(fileStream) val worksheet: IWorksheet = workbook.getWorksheets().get(0) //Export the chart to image worksheet.getShapes().get("ProductIncomeChart").toImage(outputStream, ImageType.PNG) // End using the file stream }