poi向Excel模板动态添加行

List<InspectionEnclosure> enclosureList = enclosureDao.getEnclosureByFatherId(bridgeSpace.getId()); int tofirstMer = 0; if(enclosureList!=null&&enclosureList.size()>0){ int a = 0; for(int j =0;j<enclosureList.size();j++){//循环向Excel模板中插入图片 if(enclosureList.get(j).getDocumentURL()!=null&&!"".equals(enclosureList.get(j).getDocumentURL())){ try { BufferedImage bufferImg = null; ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); bufferImg = ImageIO.read(new File(URLDecoder.decode(request.getSession().getServletContext().getRealPath(enclosureList.get(j).getDocumentURL().split("ACInspection")[1]),"utf-8"))); ImageIO.write(bufferImg, "png", byteArrayOut); Drawing patriarch = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0,(short) 0, (25+a), (short) 7, (30+a)); patriarch.createPicture(anchor, workbook.addPicture(byteArrayOut.toByteArray(), workbook.PICTURE_TYPE_PNG)); } catch (IOException e) { e.printStackTrace(); } a+=6; }
                                        //由于模板大小固定,图片过多会将模板覆盖,需动态增加模板行数 for(int x=0;x<6;x++){ sheet.shiftRows(25, sheet.getLastRowNum(), 1,true,false); sheet.createRow(25); tofirstMer++; } } }
 
//合并插入的行
CellRangeAddress region4 = new CellRangeAddress(50,50+tofirstMer,(short)0,(short)7); sheet.addMergedRegion(region4);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值