锁定老帖子 主题:将树节点以列方式导出EXCEL
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (1)
|
|
---|---|
作者 | 正文 |
发表时间:2011-10-08
终于搞定了,将成果展示一下。。。
/** * 导出业务线下的模板信息 * @return */ public String exportServiceLine(){ try { Integer parentId = serviceLineh.getId(); List<ServiceLined> lineds = mgr.selectAllChild(parentId, true); List<ServiceLined> plineds=new ArrayList<ServiceLined>(); List<ServiceLined> slineds=new ArrayList<ServiceLined>(); List<ServiceLined> llineds=new ArrayList<ServiceLined>(); if(lineds!=null&&lineds.size()>0){ logger.debug("lineds**********************"+lineds.size()); ServiceLined param = new ServiceLined(); param.setParentid(parentId); param.setOther(Constant.IS_ROOT); ServiceLined rlined = mgr.findRootLined(param); logger.debug("rlined.id*****************************"+rlined.getId()); for (int i = 1; i < lineds.size(); i++) { ServiceLined lined = lineds.get(i); logger.debug("equals**************"+lined.getParentid().equals(rlined.getId())); if (lined.getParentid().equals(rlined.getId())) { //int countSub = mgr.findCountSubLined(lined); plineds.add(lined); } } logger.debug("plineds**********************"+plineds.size()); if (plineds.size()>0) { for (int i = 0; i < plineds.size(); i++) { for (int j = 1; j < lineds.size(); j++) { ServiceLined lined = lineds.get(j); if(plineds.get(i).getId().equals(lined.getParentid())){ slineds.add(lined); } } } logger.debug("slineds**********************"+slineds.size()); logger.debug("lineds**********************"+lineds.size()); if(slineds.size()>0){ for (int i = 0; i < slineds.size(); i++) { for (int j = 0; j < lineds.size(); j++) { ServiceLined lined = lineds.get(j); if (slineds.get(i).getId().equals(lined.getParentid())) { llineds.add(lined); } } } } logger.debug("llineds**********************"+llineds.size()); } OutputStream os = new FileOutputStream(new File("f://test.xls")); WritableWorkbook book = Workbook.createWorkbook(os); WritableSheet sheet=book.createSheet("test", 0); sheet.setColumnView(0, 20); sheet.setColumnView(1, 20); sheet.setColumnView(2, 60); sheet.setRowView(0, 500); WritableCellFormat wcff= new WritableCellFormat(); wcff.setWrap(true); wcff.setShrinkToFit(true); Label lableBuh=new Label(0,0,"父节点信息",wcff); Label lableBuh2=new Label(1,0,"子节点信息",wcff); Label lableBuh3=new Label(2,0,"叶节点信息",wcff); sheet.addCell(lableBuh); sheet.addCell(lableBuh2); sheet.addCell(lableBuh3); int count = 1; Label lableBu=new Label(0,count,"",wcff); Label lableBu2=new Label(1,count,"",wcff); Label lableBu3=new Label(2,count,"",wcff); boolean flag = false; if (plineds.size()>0) { for (int i = 0; i < plineds.size(); i++) { lableBu = new Label(0,count,plineds.get(i).getNode(),wcff); int countSubject = mgr.findCountSubLined(plineds.get(i)); sheet.addCell(lableBu); if (countSubject>1) { sheet.mergeCells(0, count, 0, count+countSubject-1); } if(slineds.size()>0){ for (int j = 0; j < slineds.size(); j++) { if (plineds.get(i).getId().equals(slineds.get(j).getParentid())) { lableBu2=new Label(1,count,slineds.get(j).getNode(),wcff); sheet.addCell(lableBu2); if(llineds.size()>0){ String nodeName = ""; for (int k = 0; k < llineds.size(); k++) { if (slineds.get(j).getId().equals(llineds.get(k).getParentid())) { nodeName += llineds.get(k).getNode()+" "; int countSub = mgr.findCountSubLined(llineds.get(k)); if (countSub>0) { for (int l = 0; l < lineds.size(); l++) { if (llineds.get(k).getId().equals(lineds.get(l).getParentid())) { nodeName += "\n "+lineds.get(l).getNode(); countSub = mgr.findCountSubLined(lineds.get(l)); if (countSub>0) { for (int m = 0; m < lineds.size(); m++) { if (lineds.get(l).getId().equals(lineds.get(m).getParentid())) { nodeName += "\n "+lineds.get(m).getNode()+" "; } } } } } } lableBu3 = new Label(2,count,nodeName,wcff); sheet.addCell(lableBu3); //count++; } } } count++; flag = true; } } } if (!flag) { count++; } } } book.write(); book.close(); os.close(); //getResponse().setContentType("text/html;charset=utf-8"); //getResponse().getWriter().print("导出业务线模板信息成功!"); } } catch (Exception e) { logger.error(e); } return null; } |
|
返回顶楼 | |