乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > 如何使rtf的内容作为<em>html</em>显示-poi word to html,poiw

如何使rtf的内容作为<em>html</em>显示-poi word to html,poiw

作者:乔山办公网日期:

返回目录:word文档


所需要的原料:Word2007版

解决Word文档打开总是显示修订的步骤:

  1. 首先,打开修订过的文档

  2. 点击工具栏中“审阅”找到zhidao“修订”,在修订工具下方找到小箭头,并点击,出现下拉菜单,选择“修订选项”

  3. 在弹出的“修订选项”设置框中,找到“批注框”

  4. 在“使用批注框”选项后面选择“从不”,并点击“确定”

  5. 然后工具栏“审阅”中,找到“接受”栏,点击下方的小箭头,出现下拉菜单,选中“接受对所有文档的修订”

  6. 再打开 文档,将不会再显示修订了



stra="[<table>]"
stra=stra+"<tr><td>"
stra=stra+"你好!"
stra=stra+"</td></tr>"
stra=stra+"<table>]"
doc.rtf=stra

以WPS 2019版为例

打开文档,依次点击“审阅”--->“显示标记”



实现代码如下:
public class Word2Html { public static void main(String argv[]) { try { //word 路径 html输出路径 convert2Html("D:/doctohtml/1.doc","D:/doctohtml/1.html"); } catch (Exception e) { e.printStackTrace(); } } public static void writeFile(String content, String path) { FileOutputStream fos = null; BufferedWriter bw = null; try { File file = new File(path); fos = new FileOutputStream(file); bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8")); bw.write(content); } catch (FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (bw != null) bw.close(); if (fos != null) fos.close(); } catch (IOException ie) { } } } public static void convert2Html(String fileName, String outPutFile) throws TransformerException, IOException, ParserConfigurationException { HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile)); WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter( DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument()); wordToHtmlConverter.setPicturesManager( new PicturesManager() { public String savePicture( byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches ) { //html 中 图片标签中 显示的图片路路径 <img src="d:/test/0.jpg"/> return "d:/doctohtml/"+suggestedName; } } ); wordToHtmlConverter.processDocument(wordDocument); //save pictures List pics=wordDocument.getPicturesTable().getAllPictures(); if(pics!=null){ for(int i=0;i<pics.size();i++){ Picture pic = (Picture)pics.get(i); System.out.println(); try { //word中图7a686964616fe78988e69d83365片的存储路径 pic.writeImageContent(new FileOutputStream("D:/doctohtml/" + pic.suggestFullFileName())); } catch (FileNotFoundException e) { e.printStackTrace(); } } } Document htmlDocument = wordToHtmlConverter.getDocument(); ByteArrayOutputStream out = new ByteArrayOutputStream(); DOMSource domSource = new DOMSource(htmlDocument); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.transform(domSource, streamResult); out.close(); writeFile(new String(out.toByteArray()), outPutFile); }}

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网