zoukankan      html  css  js  c++  java
  • 使用EasyPoi导出Excel

    Excel模板来自自己写死的一个excel模板,相当于是用户查询数据,数据填充到一个模板的Excel里,再导出Excel

    /*创建模板*/
    String a= request.getSession().getServletContext().getRealPath("/resource/河南能源化工集团安全监控系统联网系统瓦斯涌出异常信息表.xlsx");

    获取模板

    TemplateExportParams params=new TemplateExportParams(a);

    获取查询数据,将数据放到map里面,自定义的excel的单元格里获取map的key值

    List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
    for(int i=0;i<list.size();i++){
    Map<String, String> ma = new HashMap<String, String>();
    ma.put("xh", String.valueOf(i+1));
    ma.put("mygs", list.get(i).getGs());
    ma.put("kjmc", list.get(i).getMineName());
    ma.put("dd", list.get(i).getLocation());
    ma.put("zdz", list.get(i).getNowmaxvalue());
    ma.put("zdzsk", list.get(i).getNowtime());
    ma.put("three", list.get(i).getTheaybeforeValue());
    ma.put("two", list.get(i).getTwodaysagoValue());
    ma.put("one", list.get(i).getTheaybeforeValue());
    ma.put("nowzdz", list.get(i).getNowmaxvalue());
    listMap.add(ma);
    }
    map.put("listmap", listMap);

    modelMap.put(TemplateExcelConstants.FILE_NAME, "河南能源化工集团安全监控系统联网系统瓦斯涌出异常信息表"); //文件名
    modelMap.put(TemplateExcelConstants.PARAMS, params);//参数
    modelMap.put(TemplateExcelConstants.MAP_DATA, map);//数据
    return TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW;//view名称

    SpringWeb中,需要在spring-mvc.xml中引入处理Excel的配置

    <!-- Excel 处理 根据用户输入进行对象处理 -->
    <bean id="jeecgExcelView" class="org.jeecgframework.poi.excel.view.JeecgSingleExcelView" />
    <bean id="jeecgTemplateExcelView" class="org.jeecgframework.poi.excel.view.JeecgTemplateExcelView" />
    <bean id="jeecgTemplateWordView" class="org.jeecgframework.poi.excel.view.JeecgTemplateWordView" />
    <bean id="jeecgMapExcelView" class="org.jeecgframework.poi.excel.view.JeecgMapExcelView" />

    导出结果

  • 相关阅读:
    Shortcut key for WPF
    Make webclient support upload the large file which are larger than 1G
    Decodes a QuotedPrintable encoded string
    C# USB Detection winform and WPF
    [转] 线程同步
    C# x86应用x64系统上读取x64位应用的注册表
    CSS Sprites图片拼合生成器实现思路
    python 复制文件
    Resources: Tips of Notepad++
    ASP.net MVC与RESTful ROA的思想还是有点区别的
  • 原文地址:https://www.cnblogs.com/LiaoYunChuan/p/9947435.html
Copyright © 2011-2022 走看看