/** * 获得传递打印所需参数,打印付款通知单 * * @return */ public String getPrintParameter() { log.info("打印付款通知单"); try { //合同的编号,MIS项目编号 String contractCode = contractVO.getContractCode(); String misCode = printPaymentAdivceService.findMisByContractId(contractVO.getContractId()); // 获得项目根目录 String contextPath = this.getServletContext().getRealPath("/"); //读取模板 String downloadFile = contextPath +"templatefile" + File.separator + "printpaymentadvice" + File.separator + "fktzd.xls"; POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(downloadFile)); //动态向模板写入数据 HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFFont font = wb.createFont(); font.setFontHeightInPoints((short) 12); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // Fonts are set into a style so create a new one to use. HSSFCellStyle style = wb.createCellStyle(); style.setFont(font); HSSFRow row = null; HSSFCell cell = null; HSSFCell cell1 = null; row = sheet.getRow(1); cell = row.getCell((short) 1); cell.setCellValue(contractCode); cell.setCellStyle(style); cell1 = row.getCell((short) 3); cell1.setCellValue(misCode); cell1.setCellStyle(style); //存储到服务器 或磁盘 // wb.write(new FileOutputStream(contextPath +"templatefile" + File.separator + "printpaymentadvice" + File.separator + contractCode + ".xls")); //往页面上写 String fileOldName = "付款通知单-" + contractCode + ".xls"; fileOldName = new String(fileOldName.getBytes("GB2312"),"ISO-8859-1"); this.getResponse().reset(); this.getResponse().addHeader("Content-Disposition","attachment; filename=/"" + fileOldName + "/""); this.getResponse().setContentType("application/octet-stream"); OutputStream output = this.getResponse().getOutputStream(); wb.write(output); output.flush(); output.close(); return null; } catch (Exception e) { log.error("打印付款通知单出错了", e); e.printStackTrace(); } return SUCCESS; }