Package org.apache.poi.hssf.usermodel

Examples of org.apache.poi.hssf.usermodel.HSSFClientAnchor


      Object obj, Workbook workbook) throws Exception {
    if(StringUtils.isEmpty(field)){return;}
    row.setHeight((short) (50 * entity.getHeight()));
    row.createCell(i);
    ClientAnchor anchor = workbook instanceof HSSFWorkbook?
        new HSSFClientAnchor(0, 0, 0, 0, (short) i,
        row.getRowNum(), (short) (i + 1), row.getRowNum() + 1):
          new XSSFClientAnchor(0, 0, 0, 0, (short) i,
              row.getRowNum(), (short) (i + 1), row.getRowNum() + 1);
    if (entity.getExportImageType() == 1) {
      ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
View Full Code Here


        HSSFWorkbook workbook) { 
        Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
        List<HSSFPictureData> pictures = workbook.getAllPictures()
        if (pictures.size() != 0) { 
            for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) { 
                HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor()
                if (shape instanceof HSSFPicture) { 
                    HSSFPicture pic = (HSSFPicture) shape; 
                    int pictureIndex = pic.getPictureIndex() - 1
                    HSSFPictureData picData = pictures.get(pictureIndex)
                    String picIndex = String.valueOf(anchor.getRow1()) + "_" 
                            + String.valueOf(anchor.getCol1())
                    sheetIndexPicMap.put(picIndex, picData)
                }
            } 
            return sheetIndexPicMap; 
        } else
View Full Code Here

   */
  private static void createImageCell(Drawing patriarch, ExcelExportEntity entity, Row row,
      int i, String string, Object obj) throws Exception {
    row.setHeight((short) (50*entity.getHeight()));
    row.createCell(i);
    HSSFClientAnchor anchor = new HSSFClientAnchor(
              0,0,0,0, (short) i, row.getRowNum(),
              (short) (i+1),row.getRowNum()+1);
    if(StringUtils.isEmpty(string)){return;}
    if(entity.getExportImageType()==1){
      ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
View Full Code Here

        return pictures;
    }

    public static void searchForAnchors(List escherRecords, List<HSSFClientAnchor> pictures) {
        Iterator recordIter = escherRecords.iterator();
        HSSFClientAnchor anchor = null;
        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);
            }
        }
View Full Code Here

      // Could be a group, or a base object
      if(shapeContainer.getChildRecords().size() == 1 &&
          shapeContainer.getChildContainers().size() == 1) {
        // Group
        HSSFShapeGroup group =
          new HSSFShapeGroup(null, new HSSFClientAnchor());
        patriarch.getChildren().add(group);

        EscherContainerRecord groupContainer =
          (EscherContainerRecord)shapeContainer.getChild(0);
        convertRecordsToUserModel(groupContainer, group);
      } else if(shapeContainer.hasChildOfType((short)0xF00D)) {
        // TextBox
        HSSFTextbox box =
          new HSSFTextbox(null, new HSSFClientAnchor());
        patriarch.getChildren().add(box);

        convertRecordsToUserModel(shapeContainer, box);
      } else if(shapeContainer.hasChildOfType((short)0xF011)) {
        // Not yet supporting EscherClientDataRecord stuff
View Full Code Here

    private void addImageToSheet(int colNumber, int rowNumber, HSSFSheet sheet,
            String imageFile, double reqImageWidthMM, double reqImageHeightMM,
            int resizeBehaviour) throws FileNotFoundException, IOException,
                                                     IllegalArgumentException  {
        HSSFRow row = null;
        HSSFClientAnchor anchor = null;
        HSSFPatriarch patriarch = null;
        ClientAnchorDetail rowClientAnchorDetail = null;
        ClientAnchorDetail colClientAnchorDetail = null;

        // Validate the resizeBehaviour parameter.
        if((resizeBehaviour != AddDimensionedImage.EXPAND_COLUMN) &&
           (resizeBehaviour != AddDimensionedImage.EXPAND_ROW) &&
           (resizeBehaviour != AddDimensionedImage.EXPAND_ROW_AND_COLUMN) &&
           (resizeBehaviour != AddDimensionedImage.OVERLAY_ROW_AND_COLUMN)) {
            throw new IllegalArgumentException("Invalid value passed to the " +
                    "resizeBehaviour parameter of AddDimensionedImage.addImageToSheet()");
        }

        // Call methods to calculate how the image and sheet should be
        // manipulated to accomodate the image; columns and then rows.
        colClientAnchorDetail = this.fitImageToColumns(sheet, colNumber,
                reqImageWidthMM, resizeBehaviour);
        rowClientAnchorDetail = this.fitImageToRows(sheet, rowNumber,
                reqImageHeightMM, resizeBehaviour);

        // Having determined if and how to resize the rows, columns and/or the
        // image, create the HSSFClientAnchor object to position the image on
        // the worksheet. Note how the two ClientAnchorDetail records are
        // interrogated to recover the row/column co-ordinates and any insets.
        // The first two parameters are not used currently but could be if the
        // need arose to extend the functionality of this code by adding the
        // ability to specify that a clear 'border' be placed around the image.
        anchor = new HSSFClientAnchor(0,
                                      0,
                                      colClientAnchorDetail.getInset(),
                                      rowClientAnchorDetail.getInset(),
                                      (short)colClientAnchorDetail.getFromIndex(),
                                      rowClientAnchorDetail.getFromIndex(),
                                      (short)colClientAnchorDetail.getToIndex(),
                                      rowClientAnchorDetail.getToIndex());

        // For now, set the anchor type to do not move or resize the
        // image as the size of the row/column is adjusted. This could easilly
        // become another parameter passed to the method.
        //anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
        anchor.setAnchorType(HSSFClientAnchor.MOVE_AND_RESIZE);
       
        // Now, add the picture to the workbook. Note that the type is assumed
        // to be a JPEG/JPG, this could easily (and should) be parameterised
        // however.
        //int index = sheet.getWorkbook().addPicture(this.imageToBytes(imageFile),
View Full Code Here

      short column = (short) image.getColumn();
      int width = Math.abs(image.getWidth());
      int height = Math.abs(image.getHeight());

      int index = workbook.addPicture(bytes, type);
      HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, row, column, row, column);

      HSSFPatriarch patriarch = s.createDrawingPatriarch();
      HSSFPicture picture = patriarch.createPicture(anchor, index);

      picture.resize();
View Full Code Here

      short column = (short) image.getColumn();
      int width = Math.abs(image.getWidth());
      int height = Math.abs(image.getHeight());

      int index = workbook.addPicture(bytes, type);
      HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, row, column, row, column);

      HSSFPatriarch patriarch = s.createDrawingPatriarch();
      HSSFPicture picture = patriarch.createPicture(anchor, index);

      picture.resize();
View Full Code Here

      {
        // Group
        if (shapeContainer.getChildRecords().size() > 0)
        {
          HSSFShapeGroup group = new HSSFShapeGroup( null,
              new HSSFClientAnchor() );
          patriarch.getChildren().add( group );

          EscherContainerRecord groupContainer = (EscherContainerRecord) shapeContainer
              .getChild( 0 );
          convertRecordsToUserModel( groupContainer, group );
        } else
        {
          log.log( POILogger.WARN,
              "Found drawing group without children." );
        }

      } else if (shapeContainer.getRecordId() == EscherContainerRecord.SP_CONTAINER)
      {
        EscherSpRecord spRecord = shapeContainer
            .getChildById( EscherSpRecord.RECORD_ID );
        int type = spRecord.getOptions() >> 4;

        switch (type)
        {
        case ST_TEXTBOX:
          HSSFTextbox box = new HSSFTextbox( null,
              new HSSFClientAnchor() );
          patriarch.addShape( box );

          convertRecordsToUserModel( shapeContainer, box );
          break;
        case ST_PICTUREFRAME:
          // Duplicated from
          // org.apache.poi.hslf.model.Picture.getPictureIndex()
          EscherOptRecord opt = (EscherOptRecord) getEscherChild(
              shapeContainer, EscherOptRecord.RECORD_ID );
          EscherSimpleProperty prop = (EscherSimpleProperty)opt.lookup(
              EscherProperties.BLIP__BLIPTODISPLAY );
          if (prop == null)
          {
            log.log( POILogger.WARN,
                "Picture index for picture shape not found." );
          } else
          {
            int pictureIndex = prop.getPropertyValue();

            EscherClientAnchorRecord anchorRecord = (EscherClientAnchorRecord) getEscherChild(
                shapeContainer,
                EscherClientAnchorRecord.RECORD_ID );
                        HSSFClientAnchor anchor = toClientAnchor(anchorRecord);

            HSSFPicture picture = new HSSFPicture( null, anchor );
            picture.setPictureIndex( pictureIndex );
            patriarch.addShape( picture );
          }
View Full Code Here

    // back into shapes
    // log.log(POILogger.WARN, "Not processing objects into Patriarch!");
  }

    private HSSFClientAnchor toClientAnchor(EscherClientAnchorRecord anchorRecord){
        HSSFClientAnchor anchor = new HSSFClientAnchor();
        anchor.setAnchorType(anchorRecord.getFlag());
        anchor.setCol1( anchorRecord.getCol1() );
        anchor.setCol2( anchorRecord.getCol2() );
        anchor.setDx1( anchorRecord.getDx1() );
        anchor.setDx2( anchorRecord.getDx2() );
        anchor.setDy1( anchorRecord.getDy1() );
        anchor.setDy2( anchorRecord.getDy2() );
        anchor.setRow1( anchorRecord.getRow1() );
        anchor.setRow2( anchorRecord.getRow2() );
        return anchor;
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFClientAnchor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.