网上说的是因为HWPFDocument 支持doc文件,而XWPFDocument支持docx,所以会报错误。
但是,我是原本是doc文档,然后报错了之后,在网上找到了这个说法,所以直接改文件的后缀为docx,还是一直报这个错误,原来需要另存一份为docx的文件**,单单改后缀没用。。。。。
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
String templatePath = this.getClass().getClassLoader().getResource("static/doc/test.docx").getPath();
XWPFDocument document = null;
try{
//解析docx模板并获取document对象
InputStream is = new FileInputStream(templatePath);
document = new XWPFDocument(is);
ExportWordUtil.changeParagraphText(document,paragraphMap);
ExportWordUtil.changeTableText(document, tableMap);
document.write(byteOut);
} catch (IOException e) {
e.printStackTrace();
}
希望以我愚蠢的行为,为大家提供借鉴。
csdn 抽筋了?格式都用不了。


![Java使用POI技术导出Word文档,报错Package should contain a content type part [M1.13] Java使用POI技术导出Word文档,报错Package should contain a content type part [M1.13]](http://www.mshxw.com/aiimages/31/946409.png)
