POI插入图片至Excel使用固定的长宽
2017-08-10 09:09
405 查看
使用POI在Excel里插入图片,如何使插入的图片使用固定的大小?先介绍原有的两种方式:
一种是指定开始和结尾单元格,然后从头画到尾,相当于平铺
还有一种就是仅指定开始的单元格,图片的大小跟这个单元格的长宽有关,可以放大缩小固定的倍数,相当于左对齐
第一种效果如下:
View Code
原创文章,欢迎转载,转载请注明出处!
一种是指定开始和结尾单元格,然后从头画到尾,相当于平铺
还有一种就是仅指定开始的单元格,图片的大小跟这个单元格的长宽有关,可以放大缩小固定的倍数,相当于左对齐
第一种效果如下:
/** * Creates a new client anchor and sets the top-left and bottom-right * coordinates of the anchor. * * Note: Microsoft Excel seems to sometimes disallow * higher y1 than y2 or higher x1 than x2, you might need to * reverse them and draw shapes vertically or horizontally flipped! * * @param dx1 the x coordinate within the first cell. * @param dy1 the y coordinate within the first cell. * @param dx2 the x coordinate within the second cell. * @param dy2 the y coordinate within the second cell. * @param col1 the column (0 based) of the first cell. * @param row1 the row (0 based) of the first cell. * @param col2 the column (0 based) of the second cell. * @param row2 the row (0 based) of the second cell. */ public HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2, short col1, int row1, short col2, int row2) { super(dx1, dy1, dx2, dy2); checkRange(dx1, 0, 1023, "dx1"); checkRange(dx2, 0, 1023, "dx2"); checkRange(dy1, 0, 255, "dy1"); checkRange(dy2, 0, 255, "dy2"); checkRange(col1, 0, MAX_COL, "col1"); checkRange(col2, 0, MAX_COL, "col2"); checkRange(row1, 0, MAX_ROW, "row1"); checkRange(row2, 0, MAX_ROW, "row2"); setCol1((short) Math.min(col1, col2)); setCol2((short) Math.max(col1, col2)); setRow1(Math.min(row1, row2)); setRow2(Math.max(row1, row2)); if (col1 > col2){ _isHorizontallyFlipped = true; } if (row1 > row2){ _isVerticallyFlipped = true; } }
View Code
原创文章,欢迎转载,转载请注明出处!
相关文章推荐
- 使用POI向Excel中插入多张图片
- 使用POI生成Excel文件及使用POI在EXCEL文件中插入图片的方法
- 使用POI在EXCEL中插入图片
- 使用POI向Excel里插入图片
- 使用POI生成Excel文件及使用POI在EXCEL文件中插入图片的方法
- 使用POI向Excel中插入多張图片
- java POI实现向Excel中插入图片
- poi 操作excel 2007 设置 字体样式 插入图片
- POI操作Excel:插入多张图片
- POI插入EXCEL图片【成功】
- POI实现Excel插入图片
- 用POI向Excel中插入图片的例子
- java POI实现向Excel中插入图片
- java POI实现向Excel中插入图片
- java POI实现向Excel中插入图片
- java POI实现向Excel中插入图片
- POI操作Excel文档-插入图片
- 使用Npoi向Excel中插入图片
- 利用Java+POI 读写Excel文档&向Excel中插入图片
- POI操作Excel:插入多张图片