一般方式导出
try(Csv csv = CsvBuilder.of(People.class).build(getDataList())){
AttachmentExportUtil.export(csv.getFilePath(), "test.csv", response);
// csv.write(Paths.get("/User/append.csv"));
}
Map导出
Map类型为Map<String,Object>
try(Csv csv = CsvBuilder.of(Map.class).build(getMapList())){
AttachmentExportUtil.export(csv.getFilePath(), "test.csv", response);
// csv.write(Paths.get("/User/append.csv"));
}
追加方式导出
try(CsvBuilder<CsvPeople> csvBuilder = CsvBuilder.of(People.class)){
for (int i = 0; i < 10; i++) {
csvBuilder.append(data(1000));
}
Csv csv = csvBuilder.build();
AttachmentExportUtil.export(csv.getFilePath(), "test.csv", response);
// csv.write(Paths.get("/User/append.csv"));
}
二次文件追加
try(CsvBuilder<CsvPeople> csvBuilder = CsvBuilder.of(People.class).noTitles()){
for (int i = 0; i < 10; i++) {
csvBuilder.append(data(1000));
}
Csv csv = csvBuilder.build();
// 该种方式会在原append.csv文件继续追加数据,而不是覆盖
csv.write(Paths.get("/User/append.csv"),true);
}
Bean定义
public class People {
@ExcelColumn(order = 0, title = "姓名")
private String name;
@ExcelColumn(order = 1, title = "年龄")
private Integer age;
@ExcelColumn(order = 2, title = "性别")
private String gender;
}
与excel导出注解相比,支持属性减少,width、style属性将不被支持,注解请移步:注解