⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 escheraggregate.java

📁 java 报表 to office文档: 本包由java语言开发
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        int drawingRecordSize = rawEscherSize + ( shapeToObj.size() ) * 4;        int objRecordSize = 0;        for ( Iterator iterator = shapeToObj.values().iterator(); iterator.hasNext(); )        {            Record r = (Record) iterator.next();            objRecordSize += r.getRecordSize();        }        return drawingRecordSize + objRecordSize;    }    /**     * Associates an escher record to an OBJ record or a TXO record.     */    public Object assoicateShapeToObjRecord( EscherRecord r, Record objRecord )    {        return shapeToObj.put( r, objRecord );    }    public HSSFPatriarch getPatriarch()    {        return patriarch;    }    public void setPatriarch( HSSFPatriarch patriarch )    {        this.patriarch = patriarch;    }    public void clear()    {        clearEscherRecords();        shapeToObj.clear();//        lastShapeId = 1024;    }    protected String getRecordName()    {        return "ESCHERAGGREGATE";    }    // =============== Private methods ========================    private static boolean isObjectRecord( List records, int loc )    {        return sid( records, loc ) == ObjRecord.sid || sid( records, loc ) == TextObjectRecord.sid;    }    private void convertUserModelToRecords()    {        if ( patriarch != null )        {            shapeToObj.clear();            clearEscherRecords();            if ( patriarch.getChildren().size() != 0 )            {                convertPatriarch( patriarch );                EscherContainerRecord dgContainer = (EscherContainerRecord) getEscherRecord( 0 );                EscherContainerRecord spgrContainer = null;                for ( int i = 0; i < dgContainer.getChildRecords().size(); i++ )                    if ( dgContainer.getChild( i ).getRecordId() == EscherContainerRecord.SPGR_CONTAINER )                        spgrContainer = (EscherContainerRecord) dgContainer.getChild( i );                convertShapes( patriarch, spgrContainer, shapeToObj );                patriarch = null;            }        }    }    private void convertShapes( HSSFShapeContainer parent, EscherContainerRecord escherParent, Map shapeToObj )    {        if ( escherParent == null ) throw new IllegalArgumentException( "Parent record required" );        List shapes = parent.getChildren();        for ( Iterator iterator = shapes.iterator(); iterator.hasNext(); )        {            HSSFShape shape = (HSSFShape) iterator.next();            if ( shape instanceof HSSFShapeGroup )            {                convertGroup( (HSSFShapeGroup) shape, escherParent, shapeToObj );            }            else            {                AbstractShape shapeModel = AbstractShape.createShape(                        shape,                        drawingManager.allocateShapeId(drawingGroupId) );                shapeToObj.put( findClientData( shapeModel.getSpContainer() ), shapeModel.getObjRecord() );                if ( shapeModel instanceof TextboxShape )                {                    EscherRecord escherTextbox = ( (TextboxShape) shapeModel ).getEscherTextbox();                    shapeToObj.put( escherTextbox, ( (TextboxShape) shapeModel ).getTextObjectRecord() );                    //                    escherParent.addChildRecord(escherTextbox);                }                escherParent.addChildRecord( shapeModel.getSpContainer() );            }        }//        drawingManager.newCluster( (short)1 );//        drawingManager.newCluster( (short)2 );    }    private void convertGroup( HSSFShapeGroup shape, EscherContainerRecord escherParent, Map shapeToObj )    {        EscherContainerRecord spgrContainer = new EscherContainerRecord();        EscherContainerRecord spContainer = new EscherContainerRecord();        EscherSpgrRecord spgr = new EscherSpgrRecord();        EscherSpRecord sp = new EscherSpRecord();        EscherOptRecord opt = new EscherOptRecord();        EscherRecord anchor;        EscherClientDataRecord clientData = new EscherClientDataRecord();        spgrContainer.setRecordId( EscherContainerRecord.SPGR_CONTAINER );        spgrContainer.setOptions( (short) 0x000F );        spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );        spContainer.setOptions( (short) 0x000F );        spgr.setRecordId( EscherSpgrRecord.RECORD_ID );        spgr.setOptions( (short) 0x0001 );        spgr.setRectX1( shape.getX1() );        spgr.setRectY1( shape.getY1() );        spgr.setRectX2( shape.getX2() );        spgr.setRectY2( shape.getY2() );        sp.setRecordId( EscherSpRecord.RECORD_ID );        sp.setOptions( (short) 0x0002 );        int shapeId = drawingManager.allocateShapeId(drawingGroupId);        sp.setShapeId( shapeId );        if (shape.getAnchor() instanceof HSSFClientAnchor)            sp.setFlags( EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR );        else            sp.setFlags( EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_CHILD );        opt.setRecordId( EscherOptRecord.RECORD_ID );        opt.setOptions( (short) 0x0023 );        opt.addEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004 ) );        opt.addEscherProperty( new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x00080000 ) );        anchor = ConvertAnchor.createAnchor( shape.getAnchor() );//        clientAnchor.setCol1( ( (HSSFClientAnchor) shape.getAnchor() ).getCol1() );//        clientAnchor.setRow1( (short) ( (HSSFClientAnchor) shape.getAnchor() ).getRow1() );//        clientAnchor.setDx1( (short) shape.getAnchor().getDx1() );//        clientAnchor.setDy1( (short) shape.getAnchor().getDy1() );//        clientAnchor.setCol2( ( (HSSFClientAnchor) shape.getAnchor() ).getCol2() );//        clientAnchor.setRow2( (short) ( (HSSFClientAnchor) shape.getAnchor() ).getRow2() );//        clientAnchor.setDx2( (short) shape.getAnchor().getDx2() );//        clientAnchor.setDy2( (short) shape.getAnchor().getDy2() );        clientData.setRecordId( EscherClientDataRecord.RECORD_ID );        clientData.setOptions( (short) 0x0000 );        spgrContainer.addChildRecord( spContainer );        spContainer.addChildRecord( spgr );        spContainer.addChildRecord( sp );        spContainer.addChildRecord( opt );        spContainer.addChildRecord( anchor );        spContainer.addChildRecord( clientData );        ObjRecord obj = new ObjRecord();        CommonObjectDataSubRecord cmo = new CommonObjectDataSubRecord();        cmo.setObjectType( CommonObjectDataSubRecord.OBJECT_TYPE_GROUP );        cmo.setObjectId( (short) ( shapeId ) );        cmo.setLocked( true );        cmo.setPrintable( true );        cmo.setAutofill( true );        cmo.setAutoline( true );        GroupMarkerSubRecord gmo = new GroupMarkerSubRecord();        EndSubRecord end = new EndSubRecord();        obj.addSubRecord( cmo );        obj.addSubRecord( gmo );        obj.addSubRecord( end );        shapeToObj.put( clientData, obj );        escherParent.addChildRecord( spgrContainer );        convertShapes( shape, spgrContainer, shapeToObj );    }    private EscherRecord findClientData( EscherContainerRecord spContainer )    {        for ( Iterator iterator = spContainer.getChildRecords().iterator(); iterator.hasNext(); )        {            EscherRecord r = (EscherRecord) iterator.next();            if ( r.getRecordId() == EscherClientDataRecord.RECORD_ID )                return r;        }        throw new IllegalArgumentException( "Can not find client data record" );    }    private void convertPatriarch( HSSFPatriarch patriarch )    {        EscherContainerRecord dgContainer = new EscherContainerRecord();        EscherDgRecord dg;        EscherContainerRecord spgrContainer = new EscherContainerRecord();        EscherContainerRecord spContainer1 = new EscherContainerRecord();        EscherSpgrRecord spgr = new EscherSpgrRecord();        EscherSpRecord sp1 = new EscherSpRecord();        dgContainer.setRecordId( EscherContainerRecord.DG_CONTAINER );        dgContainer.setOptions( (short) 0x000F );        dg = drawingManager.createDgRecord();        drawingGroupId = dg.getDrawingGroupId();//        dg.setOptions( (short) ( drawingId << 4 ) );//        dg.setNumShapes( getNumberOfShapes( patriarch ) );//        dg.setLastMSOSPID( 0 );  // populated after all shape id's are assigned.        spgrContainer.setRecordId( EscherContainerRecord.SPGR_CONTAINER );        spgrContainer.setOptions( (short) 0x000F );        spContainer1.setRecordId( EscherContainerRecord.SP_CONTAINER );        spContainer1.setOptions( (short) 0x000F );        spgr.setRecordId( EscherSpgrRecord.RECORD_ID );        spgr.setOptions( (short) 0x0001 );    // version        spgr.setRectX1( patriarch.getX1() );        spgr.setRectY1( patriarch.getY1() );        spgr.setRectX2( patriarch.getX2() );        spgr.setRectY2( patriarch.getY2() );        sp1.setRecordId( EscherSpRecord.RECORD_ID );        sp1.setOptions( (short) 0x0002 );        sp1.setShapeId( drawingManager.allocateShapeId(dg.getDrawingGroupId()) );        sp1.setFlags( EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH );        dgContainer.addChildRecord( dg );        dgContainer.addChildRecord( spgrContainer );        spgrContainer.addChildRecord( spContainer1 );        spContainer1.addChildRecord( spgr );        spContainer1.addChildRecord( sp1 );        addEscherRecord( dgContainer );    }    /** Retrieve the number of shapes (including the patriarch). *///    private int getNumberOfShapes( HSSFPatriarch patriarch )//    {//        return patriarch.countOfAllChildren();//    }    private static short sid( List records, int loc )    {        return ( (Record) records.get( loc ) ).getSid();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -