【项目问题解决】: org/apache/xmlbeans/impl/schema/DocumentFactory docx格式文件操作问题
public static String WordToHtml(File wordFile) {
String content = null;
if (!wordFile.exists()) {
LogUtil.error("文件不存在!", null);
return null;
} else {
String parentPath = wordFile.getParent();
//String wordDir = ();
String wordName = wordFile.getName();
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();) {
//String fileOnlyName = (0, ("."));
File imageFolderFile = new File(parentPath);
String courseFile = imageFolderFile.getCanonicalPath();
com.spire.doc.Document doc = new com.spire.doc.Document();
doc.loadFromFile(parentPath+File.separator+wordName);
// 设置css样式是否被嵌入
doc.getHtmlExportOptions().setCssStyleSheetType(CssStyleSheetType.Internal);
String fileName = wordName.substring(0,wordName.lastIndexOf("."));
File docToHtml = new File(courseFile+File.separator+fileName+".html");
doc.saveToFile(docToHtml.toString());
doc.dispose();
InputStream input = new FileInputStream(docToHtml);
int ch = -1;
while((ch = input.read()) != -1){
baos.write(ch);
}
content = docxParserHtml(new String(baos.toByteArray(), HttpConstant.REQUEST_ENCODING), courseFile);
input.close();
Path path = Paths.get(courseFile+File.separator+fileName+".html");
Files.delete(path);
// XWPFDocument document = new XWPFDocument(inputStream);
// File imageFolderFile = new File(parentPath);
// String courseFile = ();
// XHTMLOptions options = ().URIResolver(new BasicURIResolver(parentPath));
// (new FileImageExtractor(imageFolderFile));
// (false);
// (true);
// ().convert(document, baos, options);
// content = parserHtml(new String((), HttpConstant.REQUEST_ENCODING), courseFile);
} catch (Exception var29) {
LogUtil.error("Word转换为Html出错", var29);
}
return content;
}
}