List of usage examples for org.apache.poi.xssf.usermodel XSSFPicture resize
public void resize()
From source file:com.netsteadfast.greenstep.util.SimpleUtils.java
License:Apache License
public static void setCellPicture(XSSFWorkbook wb, XSSFSheet sh, byte[] iconBytes, int row, int col) throws Exception { int myPictureId = wb.addPicture(iconBytes, XSSFWorkbook.PICTURE_TYPE_PNG); XSSFDrawing drawing = sh.createDrawingPatriarch(); XSSFClientAnchor myAnchor = new XSSFClientAnchor(); myAnchor.setCol1(col);//from ww w . ja v a 2 s .c o m myAnchor.setRow1(row); XSSFPicture myPicture = drawing.createPicture(myAnchor, myPictureId); myPicture.resize(); }
From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java
License:Open Source License
/** * @throws IOException//from w w w . j a v a 2 s. c o m */ public void createLogo(Workbook workbook, Sheet sheet) throws IOException { // FileInputStream obtains input bytes from the image file InputStream inputStream = new FileInputStream( new File(config.getResourcePath(), "templates" + File.separator + "logo-ccafs.png")); // Get the contents of an InputStream as a byte[]. byte[] bytes = IOUtils.toByteArray(inputStream); // Adds a picture to the workbook int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG); // close the input stream inputStream.close(); // Creates the top-level drawing patriarch. XSSFDrawing drawing = (XSSFDrawing) sheet.createDrawingPatriarch(); // Set top-left corner for the image XSSFClientAnchor anchor = new XSSFClientAnchor(); anchor.setAnchorType(2); anchor.setCol1(LOGO_POSITION_COLUMN); anchor.setRow1(LOGO_POSITION_ROW); // Creates a picture XSSFPicture pict = drawing.createPicture(anchor, pictureIdx); // Reset the image to the original size pict.resize(); }