// Create a png file stream FileOutputStream outputStream = null; try { outputStream = new FileOutputStream("ConvertShapeToImage.png"); } catch (FileNotFoundException e) { e.printStackTrace(); } // Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); // Add a oval IShape oval = worksheet.getShapes().addShape(AutoShapeType.Oval, 0, 0, 191, 194); // Set soild fill for oval oval.getFill().getColor().setRGB(Color.GetOrangeRed()); // Save the shape as image to a stream. oval.toImage(outputStream, ImageType.PNG); // Close the file stream try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); }
// Create a Image file stream FileOutputStream("ConvertShapeToImage.png").use { val outputStream = it // Create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) // Add a oval val oval = worksheet.shapes.addShape(AutoShapeType.Oval, 0.0, 0.0, 191.0, 194.0) // Set soild fill for oval oval.fill.color.rgb = Color.GetOrangeRed() // Save the shape as image to a stream. oval.toImage(outputStream, ImageType.PNG) // End using the file stream }