zoukankan      html  css  js  c++  java
  • poi 技术动态更新 Excel模板内容,动态更新内容

    1.控制器方法


    private URL base = this.getClass().getResource("");


    /**
    * 流拍之后,可以下载询价单 * * @param id 拍卖id * @param response */ @RequestMapping(value="/inquiryDownLoad",method = RequestMethod.GET) @ResponseBody public void inquiryDownLoad(String aucId,HttpServletResponse response) {
    //日志记录
    if (logger.isDebugEnabled()) { logger.debug("inquiryDownLoad, aucLotId ", aucId); }
    SimpleDateFormat sdf
    = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); AucLot aucLot = aucLotRepository.findOne(aucId); if(aucLot!=null){ SysUser sysUser=sysUserRepository.findOne(aucLot.crtUserId()); AucPrice aucPrice=aucPriceListService.findAucLotCurrentPrice(aucId);
    try { //获取模板文件的目录地址 String fileDir = new File(base.getFile(), "../../../../../../doc/").getCanonicalPath(); //获取模板文件 File demoFile=new File(fileDir + "/inquiryPrice.xls"); //这里传入一个空模板 FileInputStream in = new FileInputStream(demoFile); //创建Excel的 JAVA 对象 HSSFWorkbook book = new HSSFWorkbook(in); HSSFSheet sheet = book.getSheetAt(0);//获取Excel的第一页内容 sheet.protectSheet("123456");//设置Excel编辑密码,没有密码不可以编辑 HSSFRow row = null; HSSFCell cell=null;

              //动态更新特定坐标位置的值
    //公司留存 拍卖开始时间 row=sheet.getRow(6); cell=row.getCell(12); cell.setCellValue(sdf.format(aucLot.startTime())); //公司留存委托人姓名and手机号 row=sheet.getRow(9); cell=row.getCell(11); cell.setCellValue(aucLot.crtUserName()); row=sheet.getRow(11); cell=row.getCell(11); if(sysUser!=null && sysUser.mobile()!=null){ cell.setCellValue(sysUser.mobile().replace(sysUser.mobile().substring(3, 8), "****")); } //委托人留存 row=sheet.getRow(35); cell=row.getCell(11); cell.setCellValue(aucLot.crtUserName()); row=sheet.getRow(37); cell=row.getCell(11); if(sysUser!=null && sysUser.mobile()!=null){ cell.setCellValue(sysUser.mobile().replace(sysUser.mobile().substring(3, 8), "****")); } //拍品保留价and最高出价 row=sheet.getRow(21); cell=row.getCell(29); cell.setCellValue(aucLot.reservePrice().doubleValue()); row=sheet.getRow(22); cell=row.getCell(29); cell.setCellValue(aucPrice.price().doubleValue()); //设置下载题头 response.setContentType("application/xls"); String name = java.net.URLEncoder.encode(aucLot.goodsNo()+"测试.xls", "UTF8"); response.addHeader("Content-Disposition", "attachment; filename=" + name); ByteArrayOutputStream ostream = new ByteArrayOutputStream(); ServletOutputStream servletOS = response.getOutputStream(); book.write(ostream); servletOS.write(ostream.toByteArray()); servletOS.flush(); servletOS.close(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
  • 相关阅读:
    C#学习笔记(28)——委托排序(2)自定义排序
    C#学习笔记(27)——委托排序(1)
    C#学习笔记(26)——委托计算器
    C#学习笔记(25)——用刻盘器批量从U盘删除添加文件
    ABBYY FineReader Pro for Mac系统要求
    ABBYY FineReader错误代码142和55
    哪些因素影响ABBYY FineReader 12的识别质量
    ABBYY FineReader 12没你想得那么简单
    超强OCR文字识别软件首选ABBYY FineReader
    详解ABBYY FineReader 12扫描亮度设置
  • 原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/6407987.html
Copyright © 2011-2022 走看看