|
|
@@ -27,8 +27,8 @@ import java.util.*;
|
|
|
public class MyExcelUtil {
|
|
|
|
|
|
//根据模板导出excel
|
|
|
- public static void excelTemplteToPdf(String localPath, String templateName, Object obj) {
|
|
|
- String fileName = templateName + UUID.randomUUID().toString() + ".xlsx";
|
|
|
+ public static String excelTemplteToPdf(String localPath, String templateName, Object obj) {
|
|
|
+ String fileName = templateName + UUID.randomUUID().toString().replace("-","") + ".xlsx";
|
|
|
|
|
|
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
|
|
|
// 填充list 的时候还要注意 模板中{.} 多了个点 表示list
|
|
|
@@ -38,6 +38,9 @@ public class MyExcelUtil {
|
|
|
ExcelWriter excelWriter = null;
|
|
|
|
|
|
String filePath = localPath+File.separator + fileName;
|
|
|
+ if(!new File(filePath).getParentFile().exists()){
|
|
|
+ new File(filePath).mkdirs();
|
|
|
+ }
|
|
|
excelWriter = EasyExcel.write(filePath)
|
|
|
.withTemplate(inputStream)
|
|
|
//调用合并策略
|
|
|
@@ -56,7 +59,7 @@ public class MyExcelUtil {
|
|
|
assert excelWriter != null;
|
|
|
excelWriter.finish();
|
|
|
TestForExcel2PDF.excelToPdf(filePath,filePath.replace(".xlsx",".pdf"));
|
|
|
-
|
|
|
+ return filePath.replace(".xlsx",".pdf");
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|