jxls的excel報表效果 ,遇到什麼問題給我流言吧,我作過這方面java
仍是來點代碼吧 ,是關鍵代碼app
HttpServletRequest request = getRequest(); HttpServletResponse response = getResponse(); SimpleDateFormat tempDate = new SimpleDateFormat("yyyyMMddhhmmssSSS"); String datetime = tempDate.format(new java.util.Date()); response.setContentType("application/x-msdownload"); response.setHeader("content-disposition", "attachment; filename=" + datetime + ".xls"); List<EntrustBatchs> orglist = new ArrayList<EntrustBatchs>(); Map<String, Object> map = new HashMap<String, Object>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); map.put("year", year); map.put("month", month); map.put("bankname", orgName); map.put("tjdate", sdf.format(System.currentTimeMillis())); map.put("result1", orglist); try { String path = (getClass().getClassLoader().getResource("").toURI()).getPath(); FileInputStream is = new FileInputStream(path +"template"+File.separator+"BatchEntrustReportTemplete.xls"); // InputStream is = new FileInputStream("d:/test/cc.xls"); // 關聯模板 XLSTransformer transformer = new XLSTransformer(); HSSFWorkbook workBook = (HSSFWorkbook) transformer.transformXLS(is, map); HSSFSheet sheet = workBook.getSheetAt(0); // 合併單元格 int fork = 3; int li = orglist.size(), lj = 0, lk = 0; int b = fork; b = fork; // 合併第二列 b = fork; for (int i = 0; i < li; i++) { lj = orglist.get(i).getEntrustBatchTimes().size(); for (int j = 0; j < lj; j++) { lk = orglist.get(i).getEntrustBatchTimes().get(j).getEntrustReport().size(); int e = lk + b; sheet.addMergedRegion(new CellRangeAddress(b, e - 1, 1, 1)); sheet.addMergedRegion(new CellRangeAddress(b, e - 1, 2, 2)); b = e; b = b + 1;// 每行外部新增一行在此添加 } b = b+orglist.get(i).getEntrustBatchDate().getEntrustReport().size()+1;// 每一個分組外新增在此添加 } // 合併第一列 b = fork; for (int i = 0; i < li; i++) { lj = orglist.get(i).getEntrustBatchTimes().size(); int lkh = 0; for (int m = 0; m < lj; m++) { lkh = lkh+ orglist.get(i).getEntrustBatchTimes().get(m).getEntrustReport().size()+1; } int e = lkh + b; sheet.addMergedRegion(new CellRangeAddress(b, e - 1, 0, 0)); b = e; e = e + orglist.get(i).getEntrustBatchDate().getEntrustReport().size()+1; sheet.addMergedRegion(new CellRangeAddress(b, e - 1, 0, 0)); b = e; } OutputStream os = response.getOutputStream(); // OutputStream os = new FileOutputStream("d:/test/cc_report.xls"); workBook.write(os);
xls模板 :由於這裏不能上傳文件,我就直接粘貼代碼和圖片了
工具
項目 委託日期 手別 姓名 工號 委案狀況 撤案減數 回款狀況 回款率 組內排名 金額 個數 金額 個數 金額 個數 <jx:forEach items="${result1}" var="b"> <jx:forEach items="${b.entrustBatchTimes}" var="b1"> <jx:forEach items="${b1.entrustReport}" var="b3"> 批次明細 ${b3.commisnDate} ${b3.timesStr} ${b3.fullname} ${b3.username} ${b3.commisnmoneySum} ${b3.commisnCount} ${b3.caCommisnMoneySum} ${b3.caCommisnCount} ${b3.hkCommisnMoneySum} ${b3.hkCommisnCount} $[J7/(F7-H7)] ${b3.znSort} </jx:forEach> 在銀行內排名(委外機構排名) 1/4 合計 $[SUM(F7)] $[SUM(G7)] $[SUM(H7)] $[SUM(I7)] $[SUM(J7)] $[SUM(K7)] $[J9/(F9-H9)] </jx:forEach> <jx:forEach items="${b.entrustBatchDate.entrustReport}" var="b4"> 批次合計 ${b.entrustBatchDate.commisnDate} ${b.entrustBatchDate.timesSetStr} ${b4.fullname} ${b4.username} ${b4.commisnmoneySum} ${b4.commisnCount} ${b4.caCommisnMoneySum} ${b4.caCommisnCount} ${b4.hkCommisnMoneySum} ${b4.hkCommisnCount} $[J12/(F12-H12)] </jx:forEach> 在銀行內排名 1/4 合計 $[SUM(F12)] $[SUM(G12)] $[SUM(G12)] $[SUM(I12)] $[SUM(J12)] $[SUM(K12)] $[J14/(F14-H14)]
這是模板參考excel
下面是生成效果:code
對於生成excel的財務報表特別好,jxls已經出2.0了比以前更好更快了。 不少報表工具生成pdf,xls不少類型可是都不強大很差用,什麼report之類的 。通過篩選 jxls是最成熟 還在更新與維護,文檔也不少。更多資料就本身百度了。orm