excel中添加图片的代码
来源:互联网 发布:2016年淘宝大数据分析 编辑:程序博客网 时间:2024/05/24 06:48
直接上代码
FileOutputStream fileOut = null; BufferedImage bufferImg = null; BufferedImage bufferImgU = null; BufferedImage bufferImgP = null; BufferedImage bufferImgI= null; try { // 先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray // 读入图片1 ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); bufferImg = ImageIO.read(new File(imgPath+"/chart.png")); ImageIO.write(bufferImg, "png", byteArrayOut); // 读入图片2 ByteArrayOutputStream byteArrayOutU = new ByteArrayOutputStream(); bufferImgU = ImageIO.read(new File(imgPath+"/url.png")); ImageIO.write(bufferImgU, "png", byteArrayOutU); // 读入图片3 ByteArrayOutputStream byteArrayOutI= new ByteArrayOutputStream(); bufferImgI = ImageIO.read(new File(imgPath+"/inter.png")); ImageIO.write(bufferImgI, "png", byteArrayOutI); // 读入图片4 ByteArrayOutputStream byteArrayOutP = new ByteArrayOutputStream(); bufferImgP = ImageIO.read(new File(imgPath+"/part.png")); ImageIO.write(bufferImgP, "png", byteArrayOutP); // 创建一个工作薄 HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("test picture"); HSSFPatriarch patriarch = sheet1.createDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255, (short) 1, 1, (short) 5, 5); anchor.setAnchorType(3); HSSFClientAnchor anchoru = new HSSFClientAnchor(0, 0, 255, 255, (short) 1, 6, (short) 5, 10); anchoru.setAnchorType(3); HSSFClientAnchor anchorI = new HSSFClientAnchor(0, 0, 255, 255, (short) 6, 1, (short) 10, 5); anchorI.setAnchorType(3); HSSFClientAnchor anchorP = new HSSFClientAnchor(0, 0, 255, 255, (short) 6, 6, (short) 10, 10); anchorP.setAnchorType(3); // 插入图片1 patriarch.createPicture(anchor, wb.addPicture(byteArrayOut .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); // 插入图片2 patriarch.createPicture(anchoru, wb.addPicture(byteArrayOutU .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); // 插入图片1 patriarch.createPicture(anchorI, wb.addPicture(byteArrayOutI .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); // 插入图片2 patriarch.createPicture(anchorP, wb.addPicture(byteArrayOutP .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); fileOut = new FileOutputStream(path+"/每日报表.xls"); // 写入excel文件 wb.write(fileOut); fileOut.close(); } catch (IOException io) { io.printStackTrace(); System.out.println("erorr : " + io.getMessage()); } finally { if (fileOut != null) { try { fileOut.close(); } catch (IOException e) { e.printStackTrace(); } } }
一篇很好的介绍文章:http://blog.csdn.net/chenssy/article/details/20524563
阅读全文
0 0
- excel中添加图片的代码
- 在excel中添加图片
- C#实现使用Excel COM组件向Excel文件中添加图片的Demo
- Excel 添加图片批注
- asp.net中上传图片并生成小图片,自动添加水印的代码 .
- html中图片的添加
- 打开项目中添加的EXCEL文件
- 利用在图片上中添加文字最终生成海报的代码实现
- POI Excel 13 添加图片
- jxl添加图片到excel
- 利用using Microsoft.Office.Interop.Excel生成excel,向单元格中添加图片
- 添加图片代码片段
- poi导出Excel中图片的设置
- 获取excel中每行的图片
- excel中添加控件
- 代码中直接添加图片与文字Android
- EXCEL中图片处理
- excel 中插入图片
- Chess HDU
- 股神
- Android Api demo系列(10) (App>Activity>SetWallpaperActivity)
- **拷贝控制-拷贝、赋值、销毁(一)c++primer 5e **
- 线索二叉树
- excel中添加图片的代码
- 使用HttpClient的POST方式
- 小黑屋总结
- SQL 多表查询
- cmder 使用心得
- 云计算之路-阿里云上-容器难容:自建docker swarm集群遭遇无法解决的问题
- MySQL优化之并行复制优化(二)
- lvs、nginx和haproxy比较
- Python入门--数据类型