From a0a6f95ec5b92be03385eea83b64bf97fcbfa17e Mon Sep 17 00:00:00 2001 From: cjl <276999030@qq.com> Date: Thu, 02 Nov 2023 17:08:02 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/cjl' into dev --- screen-api/src/main/java/com/moral/api/controller/CruiserController.java | 87 +++++++++++++++++++++++++++++++++---------- 1 files changed, 66 insertions(+), 21 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/controller/CruiserController.java b/screen-api/src/main/java/com/moral/api/controller/CruiserController.java index 776c15c..c7ca622 100644 --- a/screen-api/src/main/java/com/moral/api/controller/CruiserController.java +++ b/screen-api/src/main/java/com/moral/api/controller/CruiserController.java @@ -2,11 +2,11 @@ import cn.afterturn.easypoi.word.WordExportUtil; import cn.hutool.poi.word.WordUtil; -import com.deepoove.poi.NiceXWPFDocument; import com.deepoove.poi.XWPFTemplate; -import com.deepoove.poi.data.MiniTableRenderData; +import com.deepoove.poi.config.Configure; import com.deepoove.poi.data.RowRenderData; import com.deepoove.poi.data.TextRenderData; +import com.deepoove.poi.policy.HackLoopTableRenderPolicy; import com.moral.api.entity.Dustld; import com.moral.api.pojo.bo.ExcelBO; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO; @@ -24,7 +24,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; -import org.apache.xmlbeans.impl.jam.provider.ResourcePath; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; @@ -315,29 +314,44 @@ } - public static void test( Map<String, Object> params,HttpServletResponse response) throws IOException { - InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/���������������������.docx"); - XWPFDocument compile = null; + public void test( Map<String, Object> params,HttpServletResponse response) throws IOException { + try { + //InputStream inputStream = WordUtil.class.getClassLoader().getResourceAsStream("word/���������������������.docx"); + InputStream stream = WordUtil.class.getClassLoader().getResourceAsStream("word/���������������������.docx"); + //������������������ + File file = new File("word/���������������������.docx"); + //��������������������������������������������������������������������������������������������� + FileUtils.copyInputStreamToFile(stream, file); + //��������������������������������������������� ������������������������ + String filePath = file.getAbsolutePath(); + + + //������������������������������������������������������{{}}������������������������,map������������key������������������������������������������ HashMap<String, Object> map = new HashMap<>(); //������������������������ - RowRenderData header1 = RowRenderData.build(new TextRenderData("6495ED", "������"), new TextRenderData("6495ED", "������"),new TextRenderData("6495ED", "���������������������/������������")); + //RowRenderData header1 = RowRenderData.build(new TextRenderData("6495ED", "������"), new TextRenderData("6495ED", "������"),new TextRenderData("6495ED", "���������������������/������������")); //���������������������������������������������������������list������������������������������foreach������������������ List<DustForm> list1 = (List<DustForm>) params.get("list1"); - ArrayList<Map<String, Object>> mapArrayList = (ArrayList<Map<String, Object>>) params.get("list3"); + List<Map<String, Object>> mapArrayList = (ArrayList<Map<String, Object>>) params.get("list3"); ArrayList<RowRenderData> rsList1 = new ArrayList<>(); ArrayList<RowRenderData> rsList3 = new ArrayList<>(); - + List<Map> detailList = new ArrayList<>(); for (int i = 0; i < list1.size(); i++) { DustForm dustForm = list1.get(i); - RowRenderData row0 = RowRenderData.build(i+1+"",dustForm.getRoad(), dustForm.getValue()+""); - rsList1.add(row0); + Map maps = new HashMap(); + maps.put("table1", i+1); + maps.put("table2", dustForm.getRoad()); + maps.put("table3", dustForm.getValue()); + detailList.add(maps); + /* RowRenderData row0 = RowRenderData.build(i+1+"",dustForm.getRoad(), dustForm.getValue()+""); + rsList1.add(row0);*/ } - for (int i = 0; i < mapArrayList.size(); i++) { + /*for (int i = 0; i < mapArrayList.size(); i++) { Map<String, Object> map1 = mapArrayList.get(i); RowRenderData row = RowRenderData.build(i + 1 + "", map1.get("road").toString(), map1.get("value1").toString(), map1.get("value2").toString(), map1.get("value3").toString()); rsList3.add(row); @@ -345,26 +359,57 @@ if (!ObjectUtils.isEmpty(mapArrayList)){ map.put("table3", new MiniTableRenderData(rsList3)); } - map.put("table1", new MiniTableRenderData(header1, rsList1)); + map.put("table1", new MiniTableRenderData(header1, rsList1));*/ String data = params.get("data").toString(); map.put("data",data); map.put("time",params.get("time").toString()); map.put("date1",params.get("date1").toString()); map.put("date2",params.get("date2").toString()); - File docxFile = new File("���������������������.docx"); + //map.put("detailList",detailList); + /*File docxFile = new File("���������������������.docx"); FileUtils.copyToFile(inputStream,docxFile); - compile = WordExportUtil.exportWord07(docxFile.getPath(),map); - compile.write(response.getOutputStream()); + inputStream.close();*/ + //XWPFDocument compile = WordExportUtil.exportWord07(filePath,map); + HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy(); + Configure config = Configure.newBuilder().bind("detailList", policy).build(); + + XWPFTemplate compile = XWPFTemplate.compile(filePath,config).render(new HashMap<String, Object>(){{ + put("time",map.get("time")); + put("data",map.get("data")); + put("data1",map.get("data1")); + put("data2",map.get("data2")); + put("detailList", detailList); + }}); + + response.setContentType("multipart/form-data"); + // ��������������� + response.addHeader("Content-Disposition", "attachment;fileName=ce.docx" ); + response.setCharacterEncoding("UTF-8"); + OutputStream out = response.getOutputStream(); + compile.write(out); + out.flush(); + out.close(); compile.close(); - inputStream.close(); + + + + +/* + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + compile.write(byteArrayOutputStream); + byte[] bytes = byteArrayOutputStream.toByteArray(); + response.setCharacterEncoding("utf-8"); + response.setContentType("multipart/form-data"); + response.setHeader("Content-Disposition", "attachment;filename=���������������������.docx"); + + ServletOutputStream outputStream = response.getOutputStream(); + outputStream.write(bytes); + outputStream.flush(); + outputStream.close();*/ } catch (IOException e) { log.error ("������������������������������������������", e); } catch (Exception e) { throw new RuntimeException(e); - }finally { - compile.close(); - inputStream.close(); - } } -- Gitblit v1.8.0