Package org.apache.poi.hssf.usermodel

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


        double topPos = getRowRelativePosition(layout, yCutsRow, topOffset);
        double leftPos = getColumnRelativePosition(layout, colIndex, leftOffset);
        double bottomPos = getRowRelativePosition(layout, yCutsRow, element.getHeight() - bottomOffset);
        double rightPos = getColumnRelativePosition(layout, colIndex, element.getWidth() - rightOffset);
        HSSFClientAnchor anchor =
          new HSSFClientAnchor(
            (int)((leftPos - (int)leftPos) * 1023), //numbers taken from POI source code
            (int)((topPos - (int)topPos) * 255),
            (int)((rightPos - (int)rightPos) * 1023),
            (int)((bottomPos - (int)bottomPos) * 255),
            (short)(colIndex + (int)leftPos),
            (short)(rowIndex + (int)topPos),
            //(short) (colIndex + gridCell.getColSpan()),
            (short)(colIndex + (int)rightPos),
            //rowIndex + (isCollapseRowSpan ? 1 : gridCell.getRowSpan())
            (short)(rowIndex + (int)bottomPos)
            );
        anchor.setAnchorType(2);
        //pngEncoder.setImage(bi);
        //int imgIndex = workbook.addPicture(pngEncoder.pngEncode(), HSSFWorkbook.PICTURE_TYPE_PNG);
        int imgIndex = workbook.addPicture(imageData, HSSFWorkbook.PICTURE_TYPE_PNG);
        patriarch.createPicture(anchor, imgIndex);
       
View Full Code Here


{
    public static EscherRecord createAnchor( HSSFAnchor userAnchor )
    {
        if (userAnchor instanceof HSSFClientAnchor)
        {
            HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;

            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setFlag( (short) a.getAnchorType() );
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );

            anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
            anchor.setDx2( (short) Math.max(a.getDx1(), a.getDx2()) );
            anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
            anchor.setDy2( (short) Math.max(a.getDy1(), a.getDy2() ) );
            return anchor;
        }
        else
        {
            HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
            EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
            anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
            anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
            anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
            return anchor;
        }
    }
View Full Code Here

{
    public static EscherRecord createAnchor( HSSFAnchor userAnchor )
    {
        if (userAnchor instanceof HSSFClientAnchor)
        {
            HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;

            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setFlag( (short) a.getAnchorType() );
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );

            anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
            anchor.setDx2( (short) Math.max(a.getDx1(), a.getDx2()) );
            anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
            anchor.setDy2( (short) Math.max(a.getDy1(), a.getDy2() ) );
            return anchor;
        }
        else
        {
            HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
            EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
            anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
            anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
            anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
            return anchor;
        }
    }
View Full Code Here

{
    public static EscherRecord createAnchor( HSSFAnchor userAnchor )
    {
        if (userAnchor instanceof HSSFClientAnchor)
        {
            HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;

            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setFlag( (short) a.getAnchorType() );
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );

            anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
            anchor.setDx2( (short) Math.max(a.getDx1(), a.getDx2()) );
            anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
            anchor.setDy2( (short) Math.max(a.getDy1(), a.getDy2() ) );
            return anchor;
        }
        else
        {
            HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
            EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
            anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
            anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
            anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
            return anchor;
        }
    }
View Full Code Here

{
    public static EscherRecord createAnchor( HSSFAnchor userAnchor )
    {
        if (userAnchor instanceof HSSFClientAnchor)
        {
            HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;

            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setFlag( (short) a.getAnchorType() );
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
            anchor.setDx1( (short) a.getDx1() );
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
            anchor.setDy1( (short) a.getDy1() );

            anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
            anchor.setDx2( (short) a.getDx2() );
            anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
            anchor.setDy2( (short) a.getDy2() );
            return anchor;
        }
        else
        {
            HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
            EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
            anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
            anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
            anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
            return anchor;
        }
    }
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

      {
        // Group
        final int shapeChildren = shapeContainer.getChildRecords().size();
        if (shapeChildren > 0)
        {
          HSSFShapeGroup group = new HSSFShapeGroup( parent, new HSSFClientAnchor() );
          addToParentOrContainer(group, container, parent);

          EscherContainerRecord groupContainer = (EscherContainerRecord) shapeContainer.getChild( 0 );
          convertRecordsToUserModel( groupContainer, group );
         
          if (shapeChildren>1){
            convertRecordsToUserModelRecursive(shapeContainer.getChildRecords(), container, 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.getShapeType();

        switch (type)
        {
        case ST_TEXTBOX:
          HSSFTextbox box = new HSSFTextbox( parent,
              new HSSFClientAnchor() );
          addToParentOrContainer(box, container, parent);

          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 );

            EscherChildAnchorRecord childRecord = (EscherChildAnchorRecord) getEscherChild(
                shapeContainer,
                EscherChildAnchorRecord.RECORD_ID );

            if (anchorRecord!=null && childRecord!=null){
              log.log( POILogger.WARN, "Picture with both CLIENT and CHILD anchor: "+ type );
            }
         
            HSSFAnchor anchor;
            if (anchorRecord!=null){
              anchor = toClientAnchor(anchorRecord);
            }else{
              anchor = toChildAnchor(childRecord);
            }

            HSSFPicture picture = new HSSFPicture( parent, anchor );
            picture.setPictureIndex( pictureIndex );

            addToParentOrContainer(picture, container, parent);
          }
          break;
        default:
          final HSSFSimpleShape shape = new HSSFSimpleShape( parent,
              new HSSFClientAnchor() );
          addToParentOrContainer(shape, container, parent);
          convertRecordsToUserModel( shapeContainer, shape);
         
          log.log( POILogger.WARN, "Unhandled shape type: "
              + type );
View Full Code Here

      else
        container.getChildren().add(shape);
  }

  private static 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

{
    public static EscherRecord createAnchor( HSSFAnchor userAnchor )
    {
        if (userAnchor instanceof HSSFClientAnchor)
        {
            HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;

            EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
            anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setFlag( (short) a.getAnchorType() );
            anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
            anchor.setDx1( (short) a.getDx1() );
            anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
            anchor.setDy1( (short) a.getDy1() );

            anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
            anchor.setDx2( (short) a.getDx2() );
            anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
            anchor.setDy2( (short) a.getDy2() );
            return anchor;
        }
        else
        {
            HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
            EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
            anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
            anchor.setOptions( (short) 0x0000 );
            anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
            anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
            anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
            anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
            return anchor;
        }
    }
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

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.