|
@@ -236,13 +236,7 @@ public class ExcelUtil {
|
|
|
* @param os 输出流
|
|
|
*/
|
|
|
public static void exportTemplate(List<Object> data, String templatePath, OutputStream os) {
|
|
|
- ClassPathResource templateResource = new ClassPathResource(templatePath);
|
|
|
- ExcelWriter excelWriter = EasyExcel.write(os)
|
|
|
- .withTemplate(templateResource.getStream())
|
|
|
- .autoCloseStream(false)
|
|
|
- // 大数值自动转换 防止失真
|
|
|
- .registerConverter(new ExcelBigNumberConvert())
|
|
|
- .build();
|
|
|
+ ExcelWriter excelWriter = getExcelWriter(templatePath, os);
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
if (CollUtil.isEmpty(data)) {
|
|
|
throw new IllegalArgumentException("数据为空");
|
|
@@ -254,6 +248,16 @@ public class ExcelUtil {
|
|
|
excelWriter.finish();
|
|
|
}
|
|
|
|
|
|
+ private static ExcelWriter getExcelWriter(String templatePath, OutputStream os) {
|
|
|
+ ClassPathResource templateResource = new ClassPathResource(templatePath);
|
|
|
+ return EasyExcel.write(os)
|
|
|
+ .withTemplate(templateResource.getStream())
|
|
|
+ .autoCloseStream(false)
|
|
|
+ // 大数值自动转换 防止失真
|
|
|
+ .registerConverter(new ExcelBigNumberConvert())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 多表多数据模板导出 模板格式为 {key.属性}
|
|
|
*
|
|
@@ -305,13 +309,7 @@ public class ExcelUtil {
|
|
|
* @param os 输出流
|
|
|
*/
|
|
|
public static void exportTemplateMultiList(Map<String, Object> data, String templatePath, OutputStream os) {
|
|
|
- ClassPathResource templateResource = new ClassPathResource(templatePath);
|
|
|
- ExcelWriter excelWriter = EasyExcel.write(os)
|
|
|
- .withTemplate(templateResource.getStream())
|
|
|
- .autoCloseStream(false)
|
|
|
- // 大数值自动转换 防止失真
|
|
|
- .registerConverter(new ExcelBigNumberConvert())
|
|
|
- .build();
|
|
|
+ ExcelWriter excelWriter = getExcelWriter(templatePath, os);
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
if (CollUtil.isEmpty(data)) {
|
|
|
throw new IllegalArgumentException("数据为空");
|
|
@@ -339,13 +337,7 @@ public class ExcelUtil {
|
|
|
* @param os 输出流
|
|
|
*/
|
|
|
public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
|
|
|
- ClassPathResource templateResource = new ClassPathResource(templatePath);
|
|
|
- ExcelWriter excelWriter = EasyExcel.write(os)
|
|
|
- .withTemplate(templateResource.getStream())
|
|
|
- .autoCloseStream(false)
|
|
|
- // 大数值自动转换 防止失真
|
|
|
- .registerConverter(new ExcelBigNumberConvert())
|
|
|
- .build();
|
|
|
+ ExcelWriter excelWriter = getExcelWriter(templatePath, os);
|
|
|
if (CollUtil.isEmpty(data)) {
|
|
|
throw new IllegalArgumentException("数据为空");
|
|
|
}
|