List of usage examples for org.apache.poi.hssf.usermodel HSSFClientAnchor HSSFClientAnchor
public HSSFClientAnchor()
From source file:com.haulmont.yarg.formatters.impl.xls.HSSFPicturesHelper.java
License:Apache License
public static void searchForAnchors(List escherRecords, List<HSSFClientAnchor> pictures) { Iterator recordIter = escherRecords.iterator(); HSSFClientAnchor anchor = null;//from w ww .j a va 2 s. com while (recordIter.hasNext()) { Object obj = recordIter.next(); if (obj instanceof EscherRecord) { EscherRecord escherRecord = (EscherRecord) obj; if (escherRecord instanceof EscherClientAnchorRecord) { EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord) escherRecord; if (anchor == null) anchor = new HSSFClientAnchor(); anchor.setDx1(anchorRecord.getDx1()); anchor.setDx2(anchorRecord.getDx2()); anchor.setDy1(anchorRecord.getDy1()); anchor.setDy2(anchorRecord.getDy2()); anchor.setRow1(anchorRecord.getRow1()); anchor.setRow2(anchorRecord.getRow2()); anchor.setCol1(anchorRecord.getCol1()); anchor.setCol2(anchorRecord.getCol2()); } // Recursive call. searchForAnchors(escherRecord.getChildRecords(), pictures); } } if (anchor != null) pictures.add(anchor); }
From source file:mx.avanti.siract.ui.FiltrosBeanUI.java
public HSSFSheet cabezeraGeneralExcel(HSSFSheet sheet, int logouabc, HSSFCellStyle style) { /* Create the drawing container */ HSSFPatriarch drawing = sheet.createDrawingPatriarch(); /* Create an anchor point */ ClientAnchor my_anchor = new HSSFClientAnchor(); /* Define top left corner, and we can resize picture suitable from there */ my_anchor.setCol1(1);/*from w w w . ja v a 2 s. c om*/ my_anchor.setRow1(1); /* Invoke createPicture and pass the anchor point and ID */ HSSFPicture my_picture = drawing.createPicture(my_anchor, logouabc); /* Call resize method, which resizes the image */ double escalaRes = 1; my_picture.resize(escalaRes); //definiremos el estilo para estas Celdas //Definiremos el nombre de la escuela HSSFRow row = sheet.createRow(2); row.setHeight((short) 600); HSSFCell cell = row.createCell(3); cell.setCellValue("Universidad Autnoma de Baja California"); cell.setCellStyle(style); row = sheet.createRow(3); row.setHeight((short) 600); cell = row.createCell(3); cell.setCellValue("Facultad de Ingeniera"); cell.setCellStyle(style); row = sheet.createRow(4); row.setHeight((short) 600); cell = row.createCell(3); cell.setCellValue("Mexicali"); cell.setCellStyle(style); return sheet; }
From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetAddImage.java
License:Open Source License
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException { cfSpreadSheetData spreadsheet = (cfSpreadSheetData) parameters.get(2); String imgPath = parameters.get(1).getString(); String[] anchor = parameters.get(0).getString().split(","); // Check the anchor if (anchor.length != 4 && anchor.length != 8) throwException(_session, "Invalid Anchor parameter. Must be 4 or 8 comma separated numbers"); // Determine the file type String fileExt = imgPath.substring(imgPath.lastIndexOf(".") + 1).toLowerCase(); int imgTypeIndex = 0; if (fileExt.equals("dib")) { imgTypeIndex = Workbook.PICTURE_TYPE_DIB; } else if (fileExt.equals("jpg")) { imgTypeIndex = Workbook.PICTURE_TYPE_JPEG; } else if (fileExt.equals("emf")) { imgTypeIndex = Workbook.PICTURE_TYPE_EMF; } else if (fileExt.equals("pict")) { imgTypeIndex = Workbook.PICTURE_TYPE_PICT; } else if (fileExt.equals("png")) { imgTypeIndex = Workbook.PICTURE_TYPE_PNG; } else if (fileExt.equals("wmf")) { imgTypeIndex = Workbook.PICTURE_TYPE_WMF; } else//w w w . j av a 2 s . c o m throwException(_session, "Unknown file type: " + imgPath); // Read the file FileInputStream fs = null; byte[] fileBuffer = null; try { fs = new FileInputStream(imgPath); fileBuffer = org.apache.poi.util.IOUtils.toByteArray(fs); } catch (Exception fe) { throwException(_session, "Unable to read file: " + imgPath); } finally { try { fs.close(); } catch (IOException e) { } } // Add the picture int imageIndex = spreadsheet.getWorkBook().addPicture(fileBuffer, imgTypeIndex); HSSFClientAnchor clientAnchor = new HSSFClientAnchor(); if (anchor.length == 4) { clientAnchor.setRow1(Integer.valueOf(anchor[0]) - 1); clientAnchor.setCol1(Integer.valueOf(anchor[1]) - 1); clientAnchor.setRow2(Integer.valueOf(anchor[2]) - 1); clientAnchor.setCol2(Integer.valueOf(anchor[3]) - 1); } else { clientAnchor.setDx1(Integer.valueOf(anchor[0]) - 1); clientAnchor.setDy1(Integer.valueOf(anchor[1]) - 1); clientAnchor.setDx2(Integer.valueOf(anchor[2]) - 1); clientAnchor.setDy2(Integer.valueOf(anchor[3]) - 1); clientAnchor.setRow1(Integer.valueOf(anchor[4]) - 1); clientAnchor.setCol1(Integer.valueOf(anchor[5]) - 1); clientAnchor.setRow2(Integer.valueOf(anchor[6]) - 1); clientAnchor.setCol2(Integer.valueOf(anchor[7]) - 1); } // finalise the image to the sheet spreadsheet.getActiveSheet().createDrawingPatriarch().createPicture(clientAnchor, imageIndex); return cfBooleanData.TRUE; }
From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetSetCellComment.java
License:Open Source License
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException { if (parameters.get(2).getDataType() != cfData.CFSTRUCTDATA) throwException(_session, "parameter must be of type structure"); cfSpreadSheetData spreadsheet = null; cfStructData commentS = null;//from w ww.j a v a2s . c o m int rowNo, columnNo; /* * Collect up the parameters */ spreadsheet = (cfSpreadSheetData) parameters.get(3); commentS = (cfStructData) parameters.get(2); rowNo = parameters.get(1).getInt() - 1; columnNo = parameters.get(0).getInt() - 1; if (rowNo < 0) throwException(_session, "row must be 1 or greater (" + rowNo + ")"); if (columnNo < 0) throwException(_session, "column must be 1 or greater (" + columnNo + ")"); /* * Perform the insertion */ Sheet sheet = spreadsheet.getActiveSheet(); Row row = sheet.getRow(rowNo); if (row == null) row = sheet.createRow(rowNo); Cell cell = row.getCell(columnNo); if (cell == null) cell = row.createCell(columnNo); // Create the anchor HSSFClientAnchor clientAnchor = new HSSFClientAnchor(); if (commentS.containsKey("anchor")) { String[] anchor = commentS.getData("anchor").getString().split(","); if (anchor.length != 4) throwException(_session, "Invalid 'anchor' attribute, should be 4 numbers"); clientAnchor.setRow1(Integer.valueOf(anchor[0]) - 1); clientAnchor.setCol1(Integer.valueOf(anchor[1]) - 1); clientAnchor.setRow2(Integer.valueOf(anchor[2]) - 1); clientAnchor.setCol2(Integer.valueOf(anchor[3]) - 1); } else { clientAnchor.setRow1(rowNo); clientAnchor.setCol1(columnNo); clientAnchor.setRow2(rowNo + 2); clientAnchor.setCol2(columnNo + 2); } // Create the comment Comment comment = spreadsheet.getActiveSheet().createDrawingPatriarch().createCellComment(clientAnchor); if (commentS.containsKey("author")) { comment.setAuthor(commentS.getData("author").getString()); } if (commentS.containsKey("visible")) { comment.setVisible(commentS.getData("visible").getBoolean()); } if (commentS.containsKey("comment")) { HSSFRichTextString richText = new HSSFRichTextString(commentS.getData("comment").getString()); try { richText.applyFont(SpreadSheetFormatOptions.createCommentFont(spreadsheet.getWorkBook(), commentS)); } catch (Exception e) { throwException(_session, e.getMessage()); } comment.setString(richText); } cell.setCellComment(comment); return cfBooleanData.TRUE; }
From source file:org.seasar.fisshplate.core.element.Picture.java
License:Apache License
/** * ???/*from w ww. jav a 2 s. c o m*/ * * @param width * @param height * @param cellNo * @param rowNo * @param rowRangeIntVal * @param cellRangeIntVal * @return */ private ClientAnchor createAnchor(int width, int height, int cellNo, int rowNo, int cellRangeIntVal, int rowRangeIntVal) { HSSFClientAnchor anchor = new HSSFClientAnchor(); // TODO ???????? anchor.setDx1(0); anchor.setDx2(0); anchor.setDy1(0); anchor.setDy2(255); int fromCellNo = cellNo; int toCellNo = cellNo + cellRangeIntVal; int fromRowNo = rowNo; int toRowNo = rowNo + rowRangeIntVal; anchor.setCol1((short) fromCellNo); anchor.setCol2((short) toCellNo); anchor.setRow1(fromRowNo); anchor.setRow2(toRowNo); anchor.setAnchorType(2); return anchor; }
From source file:poi.hssf.usermodel.examples.OfficeDrawing.java
License:Apache License
private static void drawOval(HSSFPatriarch patriarch) { // Create an oval and style to taste. HSSFClientAnchor a = new HSSFClientAnchor(); a.setAnchor((short) 2, 2, 20, 20, (short) 2, 2, 190, 80); HSSFSimpleShape s = patriarch.createSimpleShape(a); s.setShapeType(HSSFSimpleShape.OBJECT_TYPE_OVAL); s.setLineStyleColor(10, 10, 10);//from w ww . j av a 2s .c om s.setFillColor(90, 10, 200); s.setLineWidth(HSSFShape.LINEWIDTH_ONE_PT * 3); s.setLineStyle(HSSFShape.LINESTYLE_DOTSYS); }
From source file:poi.hssf.usermodel.examples.OfficeDrawing.java
License:Apache License
private static void drawPolygon(HSSFPatriarch patriarch) { // HSSFClientAnchor a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 2, 2, (short) 3, 3 ); // HSSFPolygon p = patriarch.createPolygon(a); // p.setPolygonDrawArea(100,100); // p.setPoints( new int[]{30, 90, 50}, new int[]{88, 5, 44} ); HSSFClientAnchor a = new HSSFClientAnchor(); a.setAnchor((short) 2, 2, 0, 0, (short) 3, 3, 1023, 255); HSSFShapeGroup g = patriarch.createGroup(a); g.setCoordinates(0, 0, 200, 200);//from ww w. j a va2 s .c o m HSSFPolygon p1 = g.createPolygon(new HSSFChildAnchor(0, 0, 200, 200)); p1.setPolygonDrawArea(100, 100); p1.setPoints(new int[] { 0, 90, 50 }, new int[] { 5, 5, 44 }); p1.setFillColor(0, 255, 0); HSSFPolygon p2 = g.createPolygon(new HSSFChildAnchor(20, 20, 200, 200)); p2.setPolygonDrawArea(200, 200); p2.setPoints(new int[] { 120, 20, 150 }, new int[] { 105, 30, 195 }); p2.setFillColor(255, 0, 0); }
From source file:poi.hssf.usermodel.examples.OfficeDrawing.java
License:Apache License
private static void drawManyLines(HSSFPatriarch patriarch) { // Draw bunch of lines int x1 = 100; int y1 = 100; int x2 = 800; int y2 = 200; int color = 0; for (int i = 0; i < 10; i++) { HSSFClientAnchor a2 = new HSSFClientAnchor(); a2.setAnchor((short) 2, 2, x1, y1, (short) 2, 2, x2, y2); HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2); shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); shape2.setLineStyleColor(color); y1 -= 10;//from w ww . j av a2 s . c om y2 -= 10; color += 30; } }
From source file:poi.hssf.usermodel.examples.OfficeDrawing.java
License:Apache License
private static void drawGrid(HSSFPatriarch patriarch) { // This draws a grid of lines. Since the coordinates space fixed at // 1024 by 256 we use a ratio to get a reasonably square grids. double xRatio = 3.22; double yRatio = 0.6711; int x1 = 000; int y1 = 000; int x2 = 000; int y2 = 200; for (int i = 0; i < 20; i++) { HSSFClientAnchor a2 = new HSSFClientAnchor(); a2.setAnchor((short) 2, 2, (int) (x1 * xRatio), (int) (y1 * yRatio), (short) 2, 2, (int) (x2 * xRatio), (int) (y2 * yRatio)); HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2); shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); x1 += 10;/*from www .ja v a 2 s. co m*/ x2 += 10; } x1 = 000; y1 = 000; x2 = 200; y2 = 000; for (int i = 0; i < 20; i++) { HSSFClientAnchor a2 = new HSSFClientAnchor(); a2.setAnchor((short) 2, 2, (int) (x1 * xRatio), (int) (y1 * yRatio), (short) 2, 2, (int) (x2 * xRatio), (int) (y2 * yRatio)); HSSFSimpleShape shape2 = patriarch.createSimpleShape(a2); shape2.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); y1 += 10; y2 += 10; } }
From source file:poi.hssf.usermodel.examples.OfficeDrawing.java
License:Apache License
private static void drawLinesToCenter(HSSFPatriarch patriarch) { // Draw some lines from and to the corners {/* w w w. ja v a 2 s . c o m*/ HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 2, 2, 0, 0, (short) 2, 2, 512, 128); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 2, 2, 512, 128, (short) 2, 2, 1024, 0); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 1, 1, 0, 0, (short) 1, 1, 512, 100); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } { HSSFClientAnchor a1 = new HSSFClientAnchor(); a1.setAnchor((short) 1, 1, 512, 100, (short) 1, 1, 1024, 0); HSSFSimpleShape shape1 = patriarch.createSimpleShape(a1); shape1.setShapeType(HSSFSimpleShape.OBJECT_TYPE_LINE); } }