use of com.alibaba.excel.ExcelWriter in project Hidoc by yuzhengyang.
the class TestController method export.
@GetMapping({ "export" })
public ResponseData export() {
String fileName = DirTool.combine(R.Paths.Temp, UUIDTool.get() + ".xlsx");
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
ExcelWriter excelWriter = EasyExcel.write(fileName, SysAccessLog.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").head(SysAccessLog.class).build();
// region 分批处理
for (int i = 0; i < 500; i++) {
List<SysAccessLog> list = sysAccessLogMapper.selectList(null);
// fillData(list);
// excelWriter.write(list, writeSheet);
}
// endregion
// //region 全量处理
// List list = new ArrayList();
// for (int i = 0; i < 500; i++) {
// List<SysAccessLog> _l = sysAccessLogMapper.selectList(null);
// list.addAll(_l);
// }
// fillData(list);
// excelWriter.write(list, writeSheet);
// //endregion
excelWriter.finish();
return ResponseData.ok();
}
use of com.alibaba.excel.ExcelWriter in project boot-admin by hb0730.
the class ExcelUtils method writeSheet.
/**
* 多页签导出
*
* @param outputStream out流
* @param data 多页签数据key为sheet名称
* @param excelTypeEnum excel类型
* @param clazz head
* @param <T> excel domain 泛型
*/
public static <T extends ExcelDomain> void writeSheet(@NonNull OutputStream outputStream, Map<String, List<T>> data, ExcelTypeEnum excelTypeEnum, Class<T> clazz) {
excelTypeEnum = excelTypeEnum == null ? ExcelTypeEnum.XLS : excelTypeEnum;
ExcelWriter writer = EasyExcel.write(outputStream, clazz).excelType(excelTypeEnum).build();
if (!CollectionUtils.isEmpty(data)) {
data.forEach((k, v) -> {
WriteSheet sheet = EasyExcel.writerSheet(k).build();
writer.write(v, sheet);
});
}
writer.finish();
}
use of com.alibaba.excel.ExcelWriter in project platform by elveahuang.
the class WriteTest method simpleWriteTest.
@Test
public void simpleWriteTest() {
File file = new File("temp/simple.xlsx");
ExcelWriter excelWriter = null;
try {
FileUtils.createParentDirectories(file);
excelWriter = EasyExcel.write(file, UserDTO.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0, "模板1").build();
excelWriter.write(Collections.EMPTY_LIST, writeSheet);
writeSheet = EasyExcel.writerSheet(1, "模板2").build();
excelWriter.write(Collections.EMPTY_LIST, writeSheet);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (excelWriter != null) {
excelWriter.finish();
}
}
}
use of com.alibaba.excel.ExcelWriter in project rebuild by getrebuild.
the class EasyExcelGenerator method generate.
/**
* @return
*/
public File generate() {
File tmp = RebuildConfiguration.getFileOfTemp(String.format("RBREPORT-%d.%s", System.currentTimeMillis(), template.getName().endsWith(".xlsx") ? "xlsx" : "xls"));
List<Map<String, Object>> datas = buildData();
// 无数据
if (datas.isEmpty())
return null;
Map<String, Object> main = null;
if (this.hasMain) {
Iterator<Map<String, Object>> iter = datas.iterator();
main = iter.next();
iter.remove();
}
ExcelWriter excelWriter = null;
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
try {
excelWriter = EasyExcel.write(tmp).withTemplate(template).build();
WriteSheet writeSheet = EasyExcel.writerSheet().registerWriteHandler(new FixsMergeStrategy()).build();
// 有明细记录
if (!datas.isEmpty()) {
excelWriter.fill(datas, fillConfig, writeSheet);
}
// 主记录
if (main != null) {
excelWriter.fill(main, writeSheet);
}
} finally {
if (excelWriter != null) {
excelWriter.finish();
}
}
return tmp;
}
use of com.alibaba.excel.ExcelWriter in project pancm_project by xuwujing.
the class EasyExcelWriteTest method excludeOrIncludeWrite.
public void excludeOrIncludeWrite() {
// 注意 simpleWrite在数据量不大的情况下可以使用(5000以内,具体也要看实际情况),数据量大参照 重复多次写入
// 写法1 JDK8+
// since: 3.0.0-beta1
String fileName = "/home" + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
// EasyExcel.write(fileName, DemoData.class)
// .sheet("模板")
// .doWrite(
// () -> {
// // 分页查询数据
// return data();
// });
// 写法2
fileName = "/home" + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
EasyExcel.write(fileName, DemoData.class).sheet("模板").doWrite(data());
// 写法3
fileName = "/home" + "/simpleWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写
ExcelWriter excelWriter = null;
try {
excelWriter = EasyExcel.write(fileName, DemoData.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet("模板").build();
excelWriter.write(data(), writeSheet);
} finally {
// 千万别忘记finish 会帮忙关闭流
if (excelWriter != null) {
excelWriter.finish();
}
}
}
Aggregations