1 16 17 package org.apache.poi.hssf.model; 18 19 import org.apache.poi.ddf.EscherRecord; 20 import org.apache.poi.ddf.EscherClientAnchorRecord; 21 import org.apache.poi.ddf.EscherChildAnchorRecord; 22 import org.apache.poi.hssf.usermodel.HSSFAnchor; 23 import org.apache.poi.hssf.usermodel.HSSFClientAnchor; 24 import org.apache.poi.hssf.usermodel.HSSFChildAnchor; 25 26 29 public class ConvertAnchor 30 { 31 public static EscherRecord createAnchor( HSSFAnchor userAnchor ) 32 { 33 if (userAnchor instanceof HSSFClientAnchor) 34 { 35 HSSFClientAnchor a = (HSSFClientAnchor) userAnchor; 36 37 EscherClientAnchorRecord anchor = new EscherClientAnchorRecord(); 38 anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID ); 39 anchor.setOptions( (short) 0x0000 ); 40 anchor.setFlag( (short) 0 ); 41 anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) ); 42 anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) ); 43 anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) ); 44 anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) ); 45 46 anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) ); 47 anchor.setDx2( (short) Math.max(a.getDx1(), a.getDx2()) ); 48 anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) ); 49 anchor.setDy2( (short) Math.max(a.getDy1(), a.getDy2() ) ); 50 return anchor; 51 } 52 else 53 { 54 HSSFChildAnchor a = (HSSFChildAnchor) userAnchor; 55 EscherChildAnchorRecord anchor = new EscherChildAnchorRecord(); 56 anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID ); 57 anchor.setOptions( (short) 0x0000 ); 58 anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) ); 59 anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) ); 60 anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) ); 61 anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) ); 62 return anchor; 63 } 64 } 65 66 } 67 | Popular Tags |