{"record":{"id":"d95968e798593dc7","repo":"jeecgboot/JeecgBoot","slug":"word-message-d95968","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/controller/AigcWordTemplateController.java","lineNumber":202,"sourceCode":"\n\n    /**\n     * 解析word模版文件\n     * @param file\n     * @param id\n     * @return\n     * @author chenrui\n     * @date 2025/7/9 14:38\n     */\n    @PostMapping(value = \"/parse/file\")\n    public Result<?> parseWOrdFile(@RequestParam(\"file\") MultipartFile file) {\n        try {\n            InputStream inputStream = file.getInputStream();\n            AigcWordTemplate eoaWordTemplate = wordTplUtils.parseWordFile(inputStream);\n            log.info(\"解析的模版信息: {}\", eoaWordTemplate);\n            return Result.OK(\"解析成功\", eoaWordTemplate);\n        } catch (Exception e) {\n            throw new RuntimeException(\"解析word模版失败: \" + e.getMessage(), e);\n        }\n    }\n\n    /**\n     * 生成word文档\n     *\n     * @param wordTplGenDTO\n     * @param response\n     * @author chenrui\n     * @date 2025/7/10 15:39\n     */\n    @PostMapping(value = \"/generate/word\")\n    public void generateWord(@RequestBody WordTplGenDTO wordTplGenDTO, HttpServletResponse response) {\n        AssertUtils.assertNotEmpty(\"参数异常\", wordTplGenDTO);\n        AigcWordTemplate template ;\n        if (oConvertUtils.isNotEmpty(wordTplGenDTO.getTemplateId())) {\n            template = eoaWordTemplateService.getById(wordTplGenDTO.getTemplateId());\n        }else{","sourceCodeStart":184,"sourceCodeEnd":220,"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/controller/AigcWordTemplateController.java#L184-L220","documentation":"parseWOrdFile() takes an uploaded MultipartFile, opens its InputStream, and parses it via wordTplUtils.parseWordFile into an AigcWordTemplate. Any failure (invalid docx, POI read error, empty stream) is thrown as a RuntimeException wrapping the cause message.","triggerScenarios":"Uploaded file is not a valid OOXML .docx (legacy .doc, .xls, or arbitrary binary); the docx is password-protected; the parse logic cannot find expected structure; InputStream empty because the multipart had no file.","commonSituations":"User uploads the wrong file type; a renamed non-docx file; corrupted upload; very large file truncated.","solutions":["Inspect the wrapped cause message and stacktrace.","Confirm the upload is a genuine .docx (open it in Word / run `unzip -l file.docx`).","Validate content type and extension before calling parseWordFile.","If the docx is valid, debug wordTplUtils.parseWordFile against the specific document."],"exampleFix":"// before\nInputStream inputStream = file.getInputStream();\nAigcWordTemplate eoaWordTemplate = wordTplUtils.parseWordFile(inputStream);\n// after - guard type and emptiness\nif (file == null || file.isEmpty()) { return Result.error(\"请上传文件\"); }\nString name = file.getOriginalFilename();\nif (name == null || !name.toLowerCase().endsWith(\".docx\")) { return Result.error(\"仅支持 .docx\"); }","handlingStrategy":"validation","validationCode":"if (file == null || file.isEmpty()) { return Result.error(\"请上传文件\"); }\nString name = file.getOriginalFilename();\nif (name == null || !name.toLowerCase().endsWith(\".docx\")) {\n    return Result.error(\"仅支持 .docx 文件\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    AigcWordTemplate t = wordTplUtils.parseWordFile(inputStream);\n    return Result.OK(\"解析成功\", t);\n} catch (RuntimeException e) {\n    log.error(\"解析word模版失败\", e);\n    return Result.error(\"解析失败，请确认文件为有效的 .docx\");\n}","preventionTips":["Validate content type and extension server-side, not just the client.","Cap upload size to avoid truncated/corrupt files."],"tags":["word","parse","upload","poi","validation"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}