利用POI中的HSSF向excel中写图片的问题
我写了一个利用POI中的HSSF向excel中写图片的方法,但是.jpg文件始终无法写入,而且会导致生成的excel文件有问题。请高手帮忙找出原因。多谢。
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFClientAnchor a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
HSSFShapeGroup group = patriarch.createGroup( a );
group.setCoordinates( 0, 0, 80 * 4 , 12 * 23 );
float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
EscherGraphics g = new EscherGraphics( group, wb, null, verticalPointsPerPixel );
g.drawOval(0,0,1023,255);
g.drawLine(0,0,1023,255);
File _file = new File("c:/サンプル.jpg"); //读入文件
Image src = javax.imageio.ImageIO.read(_file); //构造Image对象
int wideth=src.getWidth(null); //得到源图宽
int height=src.getHeight(null); //得到源图长
g.drawImage(src,0,0,wideth,height,null); //绘制缩小后的图
FileOutputStream fileOut = new FileOutputStream("ShapesandGraphics2d9.xls");
wb.write(fileOut);
fileOut.close();
g.dispose();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
HSSFClientAnchor a = new HSSFClientAnchor( 0, 0, 1023, 255, (short) 1, 0, (short) 1, 0 );
HSSFShapeGroup group = patriarch.createGroup( a );
group.setCoordinates( 0, 0, 80 * 4 , 12 * 23 );
float verticalPointsPerPixel = a.getAnchorHeightInPoints(sheet) / (float)Math.abs(group.getY2() - group.getY1());
EscherGraphics g = new EscherGraphics( group, wb, null, verticalPointsPerPixel );
g.drawOval(0,0,1023,255);
g.drawLine(0,0,1023,255);
File _file = new File("c:/サンプル.jpg"); //读入文件
Image src = javax.imageio.ImageIO.read(_file); //构造Image对象
int wideth=src.getWidth(null); //得到源图宽
int height=src.getHeight(null); //得到源图长
g.drawImage(src,0,0,wideth,height,null); //绘制缩小后的图
FileOutputStream fileOut = new FileOutputStream("ShapesandGraphics2d9.xls");
wb.write(fileOut);
fileOut.close();
g.dispose();
...全文
相关推荐
JAVA操作编辑修改office文件word,excel,ppt
JAVA如何操作编辑修改office文件word,excel,ppt
POI导出带图片的excel
利用POI技术将图片插入到excel中,希望对大家有用,直接运行ExportExcel类,即可看到效果!!!
poi操作Excel,HSSF,XSSF两种方式(.xls与.xlsx)导入导出
poi操作Excel 包含HSSF,XSSF两种方式的导入导出 支持97-2003版本的Excel与2007等高版本的Excel 下载之后eclipse导入替换jdk直接运行即可
POI操作Excel完美生成水印
POI操作Excel生成水印,该水印其实就是一个图片,该代码是将文字生成图片,再将图片变成水印的。
POI向excel中插入图片
POI向excel中插入图片


Java SE
