import com.alibaba.excel.EasyExcel;
import java.util.List;
public class TestFileUtil {
public static void downExcel(Class clz, List<?> list) {
String fileName = TestFileUtil.class.getResource("/").getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
EasyExcel.write(fileName, clz).sheet("模板").doWrite(list);
}
}
3. 调用
public class ExportTest {
@Data
@AllArgsConstructor
public static class Person {
@ExcelProperty(value = "姓名", index = 0)
private String name;
@ExcelProperty(value = "年龄", index = 1)
private String age;
}
public static void main(String[] args) {
List<Person> list = new LinkedList<>();
Person a = new Person("Tom", "12");
list.add(a);
TestFileUtil.downExcel(Person.class, list);
}
}