List of usage examples for org.apache.poi.xssf.usermodel XSSFClientAnchor setRow1
public void setRow1(int row1)
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 w ww.ja v a 2 s . co m*/ myAnchor.setRow1(row); XSSFPicture myPicture = drawing.createPicture(myAnchor, myPictureId); myPicture.resize(); }
From source file:nc.noumea.mairie.appock.util.StockSpreadsheetExporter.java
License:Open Source License
private static void addImage(XSSFWorkbook workbook, XSSFSheet worksheet, File file, int rowNum) throws IOException { //add picture data to this workbook. InputStream is = new FileInputStream(file); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG); is.close();/* ww w.ja va 2s. c o m*/ XSSFDrawing drawing = worksheet.createDrawingPatriarch(); //add a picture shape XSSFClientAnchor anchor = workbook.getCreationHelper().createClientAnchor(); anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE); //set top-left corner of the picture, //subsequent call of Picture#resize() will operate relative to it anchor.setCol1(0); anchor.setRow1(rowNum); Picture pict = drawing.createPicture(anchor, pictureIdx); //auto-size picture relative to its top-left corner pict.resize(); //get the picture width int pictWidthPx = pict.getImageDimension().width; int pictHeightPt = pict.getImageDimension().height; //get the cell width float cellWidthPx = worksheet.getColumnWidthInPixels(0); float cellHeightPx = ConvertImageUnits.heightUnits2Pixel(worksheet.getRow(rowNum).getHeight()); //calculate the center position int centerPosPx = Math.round(cellWidthPx / 2f - (float) pictWidthPx / 2f); int centerPosPy = Math.round(cellHeightPx / 2f - (float) pictHeightPt / 2f + 10); //set the new upper left anchor position anchor.setCol1(0); //set the remaining pixels up to the center position as Dx in unit EMU anchor.setDx1(centerPosPx * Units.EMU_PER_PIXEL); anchor.setDy1(centerPosPy * Units.EMU_PER_PIXEL); //resize the pictutre to original size again //this will determine the new bottom rigth anchor position pict.resize(); }
From source file:org.apache.ofbiz.pricat.AbstractPricatParser.java
License:Apache License
private void copyRow(XSSFRow sourceRow, XSSFRow targetRow, XSSFCreationHelper factory, XSSFDrawing patriarch) { for (int j = 0; j < sourceRow.getPhysicalNumberOfCells(); j++) { XSSFCell cell = sourceRow.getCell(j); if (cell != null) { XSSFCell newCell = targetRow.createCell(j); int cellType = cell.getCellType(); newCell.setCellType(cellType); switch (cellType) { case XSSFCell.CELL_TYPE_BOOLEAN: newCell.setCellValue(cell.getBooleanCellValue()); break; case XSSFCell.CELL_TYPE_ERROR: newCell.setCellErrorValue(cell.getErrorCellValue()); break; case XSSFCell.CELL_TYPE_FORMULA: newCell.setCellFormula(cell.getCellFormula()); break; case XSSFCell.CELL_TYPE_NUMERIC: newCell.setCellValue(cell.getNumericCellValue()); break; case XSSFCell.CELL_TYPE_STRING: newCell.setCellValue(cell.getRichStringCellValue()); break; default: newCell.setCellValue(formatter.formatCellValue(cell)); }/* w w w . ja v a 2 s. c o m*/ if (cell.getCellComment() != null) { XSSFClientAnchor anchor = factory.createClientAnchor(); anchor.setDx1(100); anchor.setDx2(100); anchor.setDy1(100); anchor.setDy2(100); anchor.setCol1(newCell.getColumnIndex()); anchor.setCol2(newCell.getColumnIndex() + 4); anchor.setRow1(newCell.getRowIndex()); anchor.setRow2(newCell.getRowIndex() + 4); anchor.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE); XSSFComment comment = patriarch.createCellComment(anchor); comment.setString(cell.getCellComment().getString()); newCell.setCellComment(comment); } newCell.setCellStyle(cell.getCellStyle()); newCell.getSheet().setColumnWidth(newCell.getColumnIndex(), cell.getSheet().getColumnWidth(cell.getColumnIndex())); } } }
From source file:org.cgiar.ccafs.ap.summaries.projects.xlsx.BaseXLS.java
License:Open Source License
/** * @throws IOException//from w ww. j a v a2 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(); }