|
|
@@ -17,15 +17,14 @@ import java.util.Map;
|
|
|
public class CreateExcelFileService {
|
|
|
private final WxUploadFileService wxUploadFileService;
|
|
|
private static HSSFWorkbook hWorkbook = null;
|
|
|
- private static File file = null;
|
|
|
|
|
|
@Autowired
|
|
|
public CreateExcelFileService(WxUploadFileService wxUploadFileService) {
|
|
|
this.wxUploadFileService = wxUploadFileService;
|
|
|
}
|
|
|
|
|
|
- private static void createExcelXls(String sheetName, String[] titleRow) throws Exception {
|
|
|
- file = File.createTempFile("supply", ".xls");
|
|
|
+ private File createExcelXls(String sheetName, String[] titleRow) throws Exception {
|
|
|
+ File file = File.createTempFile("supply", ".xls");
|
|
|
hWorkbook = new HSSFWorkbook();
|
|
|
|
|
|
HSSFCellStyle hSSFCellStyle = hWorkbook.createCellStyle();
|
|
|
@@ -44,9 +43,10 @@ public class CreateExcelFileService {
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
|
|
hWorkbook.write(fileOutputStream);
|
|
|
fileOutputStream.close();
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
- private void writeToExcelXls(String touserFrom, String sheetName,
|
|
|
+ private void writeToExcelXls(String touserFrom, String sheetName, File file,
|
|
|
List<Map<String, String>> mapList) throws Exception {
|
|
|
hWorkbook = new HSSFWorkbook(Files.newInputStream(file.toPath()));
|
|
|
FileOutputStream fileOutputStream;
|
|
|
@@ -73,7 +73,6 @@ public class CreateExcelFileService {
|
|
|
|
|
|
fileOutputStream = new FileOutputStream(file);
|
|
|
hWorkbook.write(fileOutputStream);
|
|
|
- System.out.println("excel文件已生成。");
|
|
|
fileOutputStream.close();
|
|
|
wxUploadFileService.upload(touserFrom, file);
|
|
|
}
|
|
|
@@ -81,8 +80,8 @@ public class CreateExcelFileService {
|
|
|
public void executeWriteExcel(String touserFrom, Map<String, List<Map<String, String>>> excelData) throws Exception {
|
|
|
String sheetName = "物料申领";
|
|
|
String[] title = {"申请人", "申请科室", "特殊情况", "库存编号", "名称", "规格", "数量", "单位"};
|
|
|
- createExcelXls(sheetName, title);
|
|
|
- writeToExcelXls(touserFrom, sheetName, excelData.get(sheetName));
|
|
|
+ File file = createExcelXls(sheetName, title);
|
|
|
+ writeToExcelXls(touserFrom, sheetName, file, excelData.get(sheetName));
|
|
|
}
|
|
|
}
|
|
|
|