easyExcel动态表头、动态行数生成、实时生成头写入、把list里的值分别写到1行的多列上

public class TestUtil {
/**
* 动态头,实时生成头写入
*


* 思路是这样子的,先创建List头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据
*
*


* 1. 创建excel对应的实体对象 参照{@link }
*


* 2. 然后写入table即可
*/

public static void main(String[] args) throws FileNotFoundException {
	String fileName = "C:/Users/HANYUN/Desktop/" + System.currentTimeMillis() + ".xlsx";
	File file = new File(fileName);
	FileOutputStream out = new FileOutputStream(file);

	EasyExcel.write(out)
			// 这里放入动态头
			.head(head()).sheet("模板")
			// 这里数据用 List<List<String>> 去传入
			.doWrite(data());

}

private static List<List<String>> head() {
	List<List<String>> list = new ArrayList<List<String>>();
	for (int i = 0; i < 10; i++) {
		List<String> head0 = new ArrayList<String>();
		head0.add("表头" + i);
		list.add(head0);
	}
	return list;
}

private static List<List<String>> data() {
	List<List<String>> list1 = new ArrayList<List<String>>();
	for (int j = 0; j < 10; j++) {
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < 10; i++) {
			list.add(i + "ss");
		}
		list1.add(list);
	}

	return list1;
}

}

瞎写点东西
select
coalesce((case when CONCAT(vsc.run_date,‘’) = ‘2021-07-01’ then max(vsc.electric_control_max) END),0) as ‘2021-07-01’ ,
(case when CONCAT(vsc.run_date,‘’) = ‘2021-07-02’ then max(vsc.electric_control_max) END) as ‘2021-07-02’ ,
(case when CONCAT(vsc.run_date,‘’) = ‘2021-07-03’ then max(vsc.electric_control_max) END) as ‘2021-07-03’ ,
(case when CONCAT(vsc.run_date,‘’) = ‘2021-07-04’ then max(vsc.electric_control_max) END) as ‘2021-07-04’ ,
coalesce((case when CONCAT(vsc.run_date,‘’) = ‘2021-07-21’ then max(vsc.electric_control_max) END),0) as ‘2021-07-21’

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值