• POI做报表


    反复查阅了jxl方式的文档,个别丢失格式问题,不能解决。只好切换到POI方式。
    POI一直开源并升级更新着。
     
    [align=center][b]根据模板导出excel[/b][/align]

    XXXAction :
    
    public ActionForward exportExcle(ActionMapping mapping,ActionForm form,
       HttpServletRequest request,HttpServletResponse response){
      DebtUtil rp = new DebtUtil();
      ActionErrors errors = new ActionErrors();
      String fileName = "";
      try{
       fileName = rp.getFileName();
      }catch(Exception e){
       errors.add("success", new ActionError("message.warn","未找到模板路径,请联系管理员!"));
       saveErrors(request, errors);
       return mapping.findForward("success");
      }
      //选择模板文件
      response.setContentType("application/x-msdownload");
      response.setHeader("Content-Disposition","attachment; filename="" +Utf8Util.toUtf8String(fileName) + """);
      // 定义输出类型
      response.setContentType("application/msexcel");
    try {
       rp.export(response.getOutputStream(),form);
    } catch (Exception e) {
       e.printStackTrace();
       logger.debug(e);
      }
      return null;
     }
    

     
    ======导出方法

    public void export(OutputStream out, ActionForm aform) throws Exception {
      HSSFWorkbook workbook;
      HSSFSheet sheet;
      HSSFRow row;
      HSSFCell cell = null;
      FileInputStream fis=null;
      try {
       // 选择模板文件
     String filePath = getModelPath("/模板");
     fis=new FileInputStream(filePath);
       workbook = new HSSFWorkbook(fis);
       sheet = workbook.getSheetAt(0);
       log.debug(filePath);
    。。。。。
    row = sheet.getRow(7);
    row.getCell(2).setCellValue(your value);
    
    workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
       workbook.write(out);
        } finally {
        workbook.close();
       if (null != out) {
        out.flush();
        out.close();
       }
       if (null != fis) 
        fis.close();
      }
    
     
    
  • 相关阅读:
    微软不也是从Altair Basic这丑小鸭长成白天鹅吗?
    互联网创业应该如何找到创意
    互联网创业创意养成记1
    安卓CTS官方文档之兼容性方案概览
    跨平台移动应用开发是否真的是一个好选择?
    Ubuntu安装MyEclise16 过程差不多
    Ubantu下安装jdk 教程
    最近出错总结
    使用Eclipse编译运行MapReduce程序 Hadoop2.6.0_Ubuntu/CentOS
    关于最近学习出现的错误,及解决的想法
  • 原文地址:https://www.cnblogs.com/zhima/p/7474834.html
Copyright © 2020-2023  润新知