zzw
2023-11-13 a22377cd06933334360c41b888ef561c5efd4512
编号
1个文件已修改
20 ■■■■ 已修改文件
core/src/main/java/com/zt/life/export/service/WordFileService.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
core/src/main/java/com/zt/life/export/service/WordFileService.java
@@ -19,13 +19,13 @@
@Service
public class WordFileService {
    public void exportWordFile(HttpServletRequest request, WordFile wordFile, HttpServletResponse response) throws UnsupportedEncodingException, FileNotFoundException {
    public void exportWordFile(HttpServletRequest request, Object dataObj, WordFile wordFile, HttpServletResponse response) throws UnsupportedEncodingException, FileNotFoundException {
        // 数据map集合
        Map<String, Object> data = new HashMap<>();
        Map<String, Object> wordData = new HashMap<>();
        //HackLoopTableRenderPolicy hackLoopTableRenderPolicy = new HackLoopTableRenderPolicy();
        Configure config = null;
        ConfigureBuilder builder = Configure.newBuilder();
        this.formatWordData(wordFile, data, builder);
        this.formatWordData(wordFile, wordData, builder);
        config = builder.build();
        File fl = new File(wordFile.getModulePath());
@@ -36,19 +36,19 @@
        } else {
            template = XWPFTemplate.compile(fs);
        }
        template.render(data);
        template.render(wordData);
        DownloadService.download(request, response, template, wordFile.getWordName());
    }
    public void formatWordData(Object obj, Map<String, Object> data, ConfigureBuilder builder) {
        Field[] fields = ReflectUtil.getFields(obj.getClass());
    public void formatWordData(Object dataObj, Map<String, Object> wordData, ConfigureBuilder builder) {
        Field[] fields = ReflectUtil.getFields(dataObj.getClass());
        for (Field field : fields) {
            field.setAccessible(true);
            String fieldName = field.getName();
            String typeName = field.getType().getName();
            Object staticFieldValue = ReflectUtil.getFieldValue(obj, field.getName()); // 属性对应的数据
            Object staticFieldValue = ReflectUtil.getFieldValue(dataObj, field.getName()); // 属性对应的数据
            if (typeName.contains("com.zt.life.modules")) {
                formatWordData(staticFieldValue, data, builder);
                formatWordData(staticFieldValue, wordData, builder);
            } else {
                if (field.getType().getName().equals("java.util.List")) {
                    builder.bind(fieldName, new HackLoopTableRenderPolicy());
@@ -60,8 +60,8 @@
                        /*put("localbyte", new PictureRenderData(80, 100, ".png", new FileInputStream("./logo.png")));*/
                    }
                }
                if (data.get(fieldName) == null)
                    data.put(fieldName, staticFieldValue);
                if (wordData.get(fieldName) == null)
                    wordData.put(fieldName, staticFieldValue);
            }
        }
    }