jeecgboot/JeecgBoot · error · RuntimeException

解析word模版失败: {message}

Error message

解析word模版失败: {message}

What it means

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.

Source

Thrown at jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/wordtpl/controller/AigcWordTemplateController.java:202


    /**
     * 解析word模版文件
     * @param file
     * @param id
     * @return
     * @author chenrui
     * @date 2025/7/9 14:38
     */
    @PostMapping(value = "/parse/file")
    public Result<?> parseWOrdFile(@RequestParam("file") MultipartFile file) {
        try {
            InputStream inputStream = file.getInputStream();
            AigcWordTemplate eoaWordTemplate = wordTplUtils.parseWordFile(inputStream);
            log.info("解析的模版信息: {}", eoaWordTemplate);
            return Result.OK("解析成功", eoaWordTemplate);
        } catch (Exception e) {
            throw new RuntimeException("解析word模版失败: " + e.getMessage(), e);
        }
    }

    /**
     * 生成word文档
     *
     * @param wordTplGenDTO
     * @param response
     * @author chenrui
     * @date 2025/7/10 15:39
     */
    @PostMapping(value = "/generate/word")
    public void generateWord(@RequestBody WordTplGenDTO wordTplGenDTO, HttpServletResponse response) {
        AssertUtils.assertNotEmpty("参数异常", wordTplGenDTO);
        AigcWordTemplate template ;
        if (oConvertUtils.isNotEmpty(wordTplGenDTO.getTemplateId())) {
            template = eoaWordTemplateService.getById(wordTplGenDTO.getTemplateId());
        }else{

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Inspect the wrapped cause message and stacktrace.
  2. Confirm the upload is a genuine .docx (open it in Word / run `unzip -l file.docx`).
  3. Validate content type and extension before calling parseWordFile.
  4. If the docx is valid, debug wordTplUtils.parseWordFile against the specific document.

Example fix

// before
InputStream inputStream = file.getInputStream();
AigcWordTemplate eoaWordTemplate = wordTplUtils.parseWordFile(inputStream);
// after - guard type and emptiness
if (file == null || file.isEmpty()) { return Result.error("请上传文件"); }
String name = file.getOriginalFilename();
if (name == null || !name.toLowerCase().endsWith(".docx")) { return Result.error("仅支持 .docx"); }
Defensive patterns

Strategy: validation

Validate before calling

if (file == null || file.isEmpty()) { return Result.error("请上传文件"); }
String name = file.getOriginalFilename();
if (name == null || !name.toLowerCase().endsWith(".docx")) {
    return Result.error("仅支持 .docx 文件");
}

Try / catch

try {
    AigcWordTemplate t = wordTplUtils.parseWordFile(inputStream);
    return Result.OK("解析成功", t);
} catch (RuntimeException e) {
    log.error("解析word模版失败", e);
    return Result.error("解析失败,请确认文件为有效的 .docx");
}

Prevention

When it happens

Trigger: 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.

Common situations: User uploads the wrong file type; a renamed non-docx file; corrupted upload; very large file truncated.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/d95968e798593dc7. Report an issue: GitHub.