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> 去传入
			.doWrite(data());

}

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

private static List> data() {
	List> list1 = new ArrayList>();
	for (int j = 0; j < 10; j++) {
		List list = new ArrayList();
		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’

你可能感兴趣的:(easyExcel,java,list,开发语言)