• 5.5 easypoi模板导出excel测试Demo > 我的程序猿之路:第四十五章


    <dependency>
         <groupId>cn.afterturn</groupId>
         <artifactId>easypoi-base</artifactId>
         <version>3.0.3</version>
    </dependency>
    <dependency>
         <groupId>cn.afterturn</groupId>
         <artifactId>easypoi-web</artifactId>
         <version>3.0.3</version>
    </dependency>
    <dependency>
         <groupId>cn.afterturn</groupId>
         <artifactId>easypoi-annotation</artifactId>
         <version>3.0.3</version>
    </dependency>
    

      

    import cn.afterturn.easypoi.excel.ExcelExportUtil;
    import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
    import org.apache.poi.ss.usermodel.Workbook;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    public class demo {
        public static void main(String[] args) throws Exception {
            new demo().excelUtil("D:\excel11\cssj.xlsx", new demo().dateMap(), "D:/excel11/专项支出用款申请书_map4.xls");
        }
    
       /**
         * @param templateUrl 模板文件路径
         * @param dateMap     文件数据
         * @param exportUrl   导出的文件路径
         */
        public void excelUtil(String templateUrl, Map<String, Object> dateMap, String exportUrl) throws Exception {
            TemplateExportParams params = new TemplateExportParams(templateUrl);
            Workbook workbook = ExcelExportUtil.exportExcel(params, dateMap);
            FileOutputStream fos = new FileOutputStream(exportUrl);
            workbook.write(fos);
            fos.close();
        }
    
    /**
         * 数据
         * @return
         */
        public Map<String, Object> dateMap() {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("date", "2014-12-25");
            map.put("money", 2000000.00);
            map.put("upperMoney", "贰佰万");
            map.put("company", "执笔潜行科技有限公司");
            map.put("bureau", "财政局");
            map.put("person", "JueYue");
            map.put("phone", "1879740****");
            List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
            for (int i = 0; i < 4; i++) {
                Map<String, String> lm = new HashMap<String, String>();
                lm.put("id", i + 1 + "");
                lm.put("zijin", i * 10000 + "");
                lm.put("bianma", "A001");
                lm.put("mingcheng", "设计");
                lm.put("xiangmumingcheng", "EasyPoi " + i + "期");
                lm.put("quancheng", "开源项目");
                lm.put("sqje", i * 10000 + "");
                lm.put("hdje", i * 10000 + "");
    
                listMap.add(lm);
            }
            map.put("maplist", listMap);
            return map;
        }
    }
    

     模板:

     

    结果:

     

  • 相关阅读:
    MDCFilter
    SpringCloud组件:Eureka服务注册用ip或主机名
    git查看分支创建于哪个分支
    关于FeignClient使用大全
    tinyint能不能保存负数
    QCon 回顾 | Data Fabric:逻辑统一、物理分散
    国产开源存储之光:Curve 通过信创认证
    有数大数据基础平台之智能运维平台EasyEagle介绍:集群队列篇
    数据治理体系演进简介
    Arctic开源!网易数帆×华泰证券,推动湖仓一体落地
  • 原文地址:https://www.cnblogs.com/fanyuyi-boke/p/12321137.html
Copyright © 2020-2023  润新知