package com.moral.api.util;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import java.io.ByteArrayOutputStream;
|
import java.io.File;
|
import java.io.IOException;
|
import java.util.List;
|
|
/**
|
* @ClassName ExcelUtil
|
* @Description TODO
|
* @Author @cjl
|
* @Date 2024-01-24 11:12
|
* @Version 1.0
|
*/
|
public class ExcelUtil {
|
public static <T> File generateExcel(String fileName, List<T> dataList, Class<T> clazz) throws IOException {
|
// 生成文件
|
File excel = new File(fileName);
|
// excel写入
|
EasyExcel.write(excel,clazz).sheet(0).doWrite(dataList);
|
return excel;
|
}
|
public static <T> ByteArrayOutputStream generateExcel(List<T> dataList, Class<T> clazz) throws IOException {
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
// excel写入
|
EasyExcel.write(out,clazz).sheet(0).doWrite(dataList);
|
return out;
|
}
|
}
|