首页 > 编程知识 正文

html转成word,word文档和doc文档的区别

时间:2023-05-03 23:18:43 阅读:164270 作者:4560

org.apache.poi

波伊

3.15

org.apache.poi

ooxml-schemas

1.4

org.apache.poi

poi-ooxml

3.15

org.apache.poi

poi-scratchpad

3.15

org.apache.poi

poi-ooxml-schemas

3.15

fr.opensagres.xdocreport

xdoc报告

2.0.2

fr.opensagres.xdocreport

org.Apache.poi.xwpf.converter.XHTML

1.0.6

首先,如果导入上面的jar包测试4.1.0 docx并将其转换为html,则会出现错误,但doc不会出现错误。 3.17也是如此,但poi3.15不会发生错误,所以请导入3.15版

publicstaticvoiddoctohtml (finalstringpath,final string文件) throws Exception{

documentbuilderfactory.new instance ().newDocumentBuilder ) )。

. newDocument ();

wordtohtmlconverter.setpicturesmanager (newpicturesmanager () ) )。

publicstringsavepicture (byte [ ] content,PictureType pictureType,

String suggestedName,float widthInches,float heightInches ) {

return suggestedName;

}

);

wordtohtmlconverter.process document (word document;

list pics=word document.getpicturestable ().getAllPictures;

if(PICS!=null ) {

for(intI=0; i pics.size (; I ) {

picturepic=(picture ) pics.get(i ) I;

pic.writeimagecontent (new file output stream ) path

pic.suggestFullFileName () );

}

}

documenthtmldocument=wordtohtmlconverter.get document (;

transformerfactorytf=transformer factory.new instance (;

transformer serializer=TF.new transformer (;

serializer.setoutputproperty (output keys.encoding,' utf-8 ' );

serializer.setoutputproperty (output keys.indent,' yes ' );

serializer.setoutputproperty (output keys.method,' html ' );

serializer.transform(DOMsource,streamResult;

outStream.close (;

string content=new string (outstream.to bytearray () );

fileutils.writestring to file (new file ) path,' 11.html ',content,' utf-8 ' );

}

publicstaticvoiddocx2html (string temppath,String fileName,String outPutFile ) throws Exception {

//导出图像

if (! strings.isnullorempty(temppath ) }

文件图像文件夹=new file (temppath );

options.set extractor (newfileimageextractor )图像文件夹);

//uri结果

options.uri resolver (newfileuriresolver )图像文件夹);

}

file outfile=new file (输出文件;

outFile.getParentFile ().mkdirs );

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。