使用POI读取模板生成多个DOCX文件压缩成zip,解压后不是一个DOCX的word文档,而是这几个文件:_rels、docProps、word、[Content_Types]
String templatePath = "D:\\模板.docx";
Zip zip = new Zip();
ByteArrayOutputStream byteArrayOutputStream = null;
Map<Long, List<CadreFamilyMemberRelation>> membersMap = getMembersMap(cadreInformations);
for (CadreInformationWord cadreInformation : cadreInformations) {
try {
XWPFDocument xwpfDocument = getXwpfDocument(cadreInformation, membersMap, templatePath);
byteArrayOutputStream = new ByteArrayOutputStream();
xwpfDocument.write(byteArrayOutputStream);
xwpfDocument.close();
byteArrayOutputStream.close();
if (cadreInformations.size() == 1) {
return result4Handle.success("导出成功!", Base64.encodeBase64String(byteArrayOutputStream.toByteArray()));
}
if (!zip.zip(cadreInformation.getCadreName() + END, byteArrayOutputStream.toByteArray())) {
log.warn("导出失败,压缩文件失败");
return result4Handle.fail("失败");
}
} catch (Exception e) {
log.warn("导出干部任免表失败");
return result4Handle.fail("失败");
}
private XWPFDocument getXwpfDocument(CadreInformationWord cadreInformation,
Map<Long, List<CadreFamilyMemberRelation>> membersMap, String templatePath) throws Exception {
FileInputStream fileInputStream = new FileInputStream(new File(templatePath));
XWPFDocument doc = new XWPFDocument(fileInputStream);
//创建文件对象
List<XWPFTable> tables = doc.getTables();
// 第一个表
List<XWPFTableRow> table1 = tables.get(0).getRows();
List<XWPFTableRow> table2 = tables.get(1).getRows();
first(cadreInformation, table1);
second(cadreInformation, table2, membersMap);
return doc;
}
怎样能让他解压后是个word文档?