先贴个代码
public static boolean replaceAndGenerateWord(String srcPath, String destPath, Map<String, String> map) throws IOException {
String[] sp = srcPath.split("\\.");
String[] dp = destPath.split("\\.");
// 判断文件有无扩展名
if (sp.length <= 0 || dp.length <= 0) {
return false;
}
if (
!sp[sp.length - 1].equalsIgnoreCase("docx")
&&
!(
sp[sp.length - 1].equalsIgnoreCase("doc")
&& dp[dp.length - 1].equalsIgnoreCase("doc")
)
) {
return false;
}
// 比较文件扩展名
if (sp[sp.length - 1].equalsIgnoreCase("docx")) {
XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(s