zoukankan      html  css  js  c++  java
  • 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;
        }
    }
    

     模板:

     

    结果:

     

  • 相关阅读:
    Velocity的使用小记
    fastJson的SerializeFilter使用
    快捷的时间转化
    How to execute a Stored Procedure with Entity Framework Code First
    自定义 ASP.NET Identity Data Model with EF
    Asp.Net Core get client IP
    HTTP 请求头中的 X-Forwarded-For
    HttpRequest,WebRequest,HttpWebRequest,WebClient,HttpClient 之间的区别
    【逻辑】500桶酒,找毒酒
    Asp.Net Core 输出 Word
  • 原文地址:https://www.cnblogs.com/fanyuyi-boke/p/12321137.html
Copyright © 2011-2022 走看看