packagecom.ultrapower.imonitor.emcc.dao.utils;importorg.apache.poi.ddf.EscherClientAnchorRecord;importorg.apache.poi.hssf.usermodel.HSSFPictureData;importorg.apache.poi.hssf.usermodel.HSSFRow;importorg.apache.poi.hssf.usermodel.HSSFSheet;importorg.apache.poi.hssf.usermodel.HSSFWorkbook;publicclassMyPictureData {privatefinalHSSFWorkbook workbook;privatefinalHSSFSheet sheet;privatefinalHSSFPictureData pictureData;privatefinalEscherClientAnchorRecord clientAnchor;publicMyPictureData(HSSFWorkbook workbook, HSSFSheet sheet, HSSFPictureData pictureData, EscherClientAnchorRecord clientAnchor) {this.workbook=workbook;this.sheet=sheet;this.pictureData=pictureData;this.clientAnchor=clientAnchor;
}publicHSSFWorkbook getWorkbook() {returnworkbook;
}publicHSSFSheet getSheet() {returnsheet;
}publicEscherClientAnchorRecord getClientAnchor() {returnclientAnchor;
}publicHSSFPictureData getPictureData() {returnpictureData;
}publicbyte[] getData() {returnpictureData.getData();
}publicString suggestFileExtension() {returnpictureData.suggestFileExtension();
}/*** 推测图片中心所覆盖的单元格,这个值不一定准确,但通常有效
*
*@returnthe row0*/publicshortgetRow0() {introw1=getRow1();introw2=getRow2();if(row1==row2) {return(short) row1;
}intheights[]=newint[row2-row1+1];for(inti=0; i
heights[i]=getRowHeight(row1+i);
}//HSSFClientAnchor 中 dx 只能在 0-1023 之间,dy 只能在 0-255 之间//表示相对位置的比率,不是绝对值intdy1=getDy1()*heights[0]/255;intdy2=getDy2()*heights[heights.length-1]/255;return(short) (getCenter(heights, dy1, dy2)+row1);
}privateshortgetRowHeight(introwIndex) {
HSSFRow row=sheet.getRow(rowIndex);shorth=row==null?sheet.getDefaultRowHeight() : row.getHeight();returnh;
}/*** 推测图片中心所覆盖的单元格,这个值不一定准确,但通常有效
*
*@returnthe col0*/publicshortgetCol0() {shortcol1=getCol1();shortcol2=getCol2();if(col1==col2) {returncol1;
}intwidths[]=newint[col2-col1+1];for(inti=0; i
widths[i]=sheet.getColumnWidth(col1+i);
}//HSSFClientAnchor 中 dx 只能在 0-1023 之间,dy 只能在 0-255 之间//表示相对位置的比率,不是绝对值intdx1=getDx1()*widths[0]/1023;intdx2=getDx2()*widths[widths.length-1]/1023;return(short) (getCenter(widths, dx1, dx2)+col1);
}/*** 给定各线段的长度,以及起点相对于起点段的偏移量,终点相对于终点段的偏移量,
* 求中心点所在的线段
*
*@parama the a 各线段的长度
*@paramd1 the d1 起点相对于起点段
*@paramd2 the d2 终点相对于终点段的偏移量
*
*@returnthe center*/protectedstaticintgetCenter(int[] a,intd1,intd2) {//线段长度intwidth=a[0]-d1+d2;for(inti=1; i
width+=a[i];
}//中心点位置intc=width/2+d1;intx=a[0];intcno=0;while(c>x) {
x+=a[cno];
cno++;
}returncno;
}/*** 左上角所在列
*
*@returnthe col1*/publicshortgetCol1() {returnclientAnchor.getCol1();
}/*** 右下角所在的列
*
*@returnthe col2*/publicshortgetCol2() {returnclientAnchor.getCol2();
}/*** 左上角的相对偏移量
*
*@returnthe dx1*/publicshortgetDx1() {returnclientAnchor.getDx1();
}/*** 右下角的相对偏移量
*
*@returnthe dx2*/publicshortgetDx2() {returnclientAnchor.getDx2();
}/*** 左上角的相对偏移量
*
*@returnthe dy1*/publicshortgetDy1() {returnclientAnchor.getDy1();
}/*** 右下角的相对偏移量
*
*@returnthe dy2*/publicshortgetDy2() {returnclientAnchor.getDy2();
}/*** 左上角所在的行
*
*@returnthe row1*/publicshortgetRow1() {returnclientAnchor.getRow1();
}/*** 右下角所在的行
*
*@returnthe row2*/publicshortgetRow2() {returnclientAnchor.getRow2();
}
}