{"record":{"id":"7647d1618e3b6509","repo":"jeecgboot/JeecgBoot","slug":"word-message-7647d1","errorCode":null,"errorMessage":"生成Word模版失败: {message}","messagePattern":"生成Word模版失败: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/wordtpl/utils/WordTplUtils.java","lineNumber":91,"sourceCode":"        WordUtil.setPaperMargins(doc, margins);\n\n        // TODO author: chenrui for:水印设置 date:2025/7/4\n\n        // 渲染页眉和页脚\n        renderHeaderAndFooter(template, doc);\n\n        // 文档主体渲染 date:2025/7/4\n        renderDocumentBody(doc, template);\n\n        // 页码\n//        addPageNumbers(doc, 0);\n\n        try {\n            doc.write(outputStream);\n            outputStream.flush();\n            doc.close();\n        } catch (Exception e) {\n            throw new RuntimeException(\"生成Word模版失败: \" + e.getMessage(), e);\n        }\n    }\n\n    /**\n     * 渲染页眉和页脚\n     *\n     * @param template\n     * @param doc\n     * @author chenrui\n     * @date 2025/7/10 17:52\n     */\n    private static void renderHeaderAndFooter(AigcWordTemplate template, XWPFDocument doc) {\n        //页眉\n        JSONArray header = JSON.parseArray(template.getHeader());\n        if (oConvertUtils.isObjectNotEmpty(header)) {\n            XWPFHeader docHeader = doc.createHeader(HeaderFooterType.DEFAULT);\n            XWPFParagraph paragraph = null;\n            for (int i = 0; i < header.size(); i++) {","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/wordtpl/utils/WordTplUtils.java#L73-L109","documentation":"WordTplUtils.generateWordTemplate() builds an XWPFDocument (header/footer/body rendering) then writes it to the supplied outputStream. The doc.write/flush/close is wrapped in a try that rethrows any IOException as a RuntimeException carrying the cause message.","triggerScenarios":"The document structure is internally inconsistent (bad relation, broken image reference); the outputStream is closed/null; an OutOfMemoryError-scaled doc; POI throws on an unsupported style/setting.","commonSituations":"Caller closed the stream before write; template definition references an image that failed to load; concurrent reuse of the same XWPFDocument; very large document exhausting memory.","solutions":["Inspect the cause message in the RuntimeException.","Validate the AigcWordTemplate fields and any image references before generation.","Ensure the passed outputStream is open, non-null, and not shared.","If OOM, raise heap or reduce document size."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure the output stream is open and writable before generation\nif (outputStream == null) { throw new IllegalArgumentException(\"outputStream 为空\"); }","typeGuard":null,"tryCatchPattern":"try (XWPFDocument doc = new XWPFDocument()) {\n    renderHeaderAndFooter(template, doc);\n    renderDocumentBody(doc, template);\n    doc.write(outputStream);\n    outputStream.flush();\n} catch (Exception e) {\n    throw new RuntimeException(\"生成Word模版失败: \" + e.getMessage(), e);\n}","preventionTips":["Do not close the outputStream from inside generateWordTemplate (caller owns it).","Validate template image references before building the doc."],"tags":["word","poi","template","io","xwpf"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}