package com.post.excel.create.postPlan;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class PostPlanTest {

    public static void main(String[] args) {
//        HttpServletResponse response = null;
//
//        List<DataBean> list = new ArrayList<>();
//        ExcelUtil<DataBean> util = new ExcelUtil<>(DataBean.class);
//
//        util.exportExcel(response, list, "岗检计划测试导出Excel");

        poiDemo();
    }

    /**
     * 项目自带的导出
     */
    public static void poiDemo() {
        List<DataBean> list = new ArrayList<>();
        ExcelUtil<DataBean> util = new ExcelUtil<>(DataBean.class);
        String sheetName = "岗检计划";
        String title = "岗位责任制检查表";
        AjaxResult ajaxResult = util.exportExcel(list, sheetName, title);
        System.out.println("ajaxResult = " + ajaxResult);
    }

    /**
     * EasyExcel 生成文件
     * 动态合并需要设置辅助列才可以实现。
     * 样式不好看
     */
    /*public static void easyExcelDemo() {
        //简单写入磁盘，官网有web写入规范，自行查看
        //https://easyexcel.opensource.alibaba.com/docs/2.x/quickstart/write#web%E4%B8%AD%E7%9A%84%E5%86%99
        String writeFile = "c:\\test\\EasyExcel_" + DateUtils.dateTimeNow() + ".xls";
        EasyExcel.write(writeFile, DataBean.class)
                .sheet("岗检计划")
                .registerWriteHandler(new DemoStyleStrategy()) //关键 注册自定义拦截器（进行单元格处理）
                .doWrite(data());

    }*/

    //案例初始化的数据  https://easyexcel.opensource.alibaba.com/docs/2.x/quickstart/write
   /* private static List<DataBean> data() {
        List<DataBean> list = ListUtils.newArrayList();
        for (int i = 0; i < 10; i++) {
            DataBean data = new DataBean();
            data.setName("字符串" + i);
            data.setContent(DateUtils.getTime());
            data.setContent2(DateUtils.getTime());
            data.setContent3(DateUtils.getTime());
            list.add(data);
        }
        return list;
    }*/

}
