poi html转word 下载 poi word转html - 电脑技术中心 - 【漳州电脑网】_漳州电脑维修_漳州笔记本电脑维修_监控安装_市区上门维修

全国统一24小时服务热线:400-0000-000400-0000-000  / 1399000000

当前位置:首页 > 电脑技术中心 > 正文

poi html转word 下载 poi word转html

发布日期:2020-10-08

摘要:java POI html转word,无法显示图片实现代码如下:public class Word2Html { public static void main(String argv[]) { tr...

poi html转word 下载

java POI html转word,无法显示图片

实现代码如下: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 中 图片标签中 显示的图片路路径 return "d:/doctohtml/"+suggestedName; } } ); wordToHtmlConverter.processDocument(wordDocument); //save pictures List pics=wordDocument.getPicturesTable().getAllPictures(); if(pics!=null){ for(int i=0;i Picture pic = (Picture)pics.get(i); System.out.println(); try { //word中图片的存储路径 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); } }

java 如何将html转换为word

new int[1]).toDispatch(),new Object[] { filePath };MS Publisher Color Printer"/** */PDFDistiller.PDFDistiller;/是否追加打印Variant Append = False.Documents的DispatchDispatch wrdDocs = wordCom.getProperty("Documents"//));/Adobe PDF"wordCom.setProperty("ActivePrinter&quot,返回wordDocwordDoc = Dispatch;/建立Adobe Distiller的com对象ActiveXComponent distiller = new ActiveXComponent("/作为输入的ps文档路径Variant inputPostScriptFilePath = new Variant(destinPSFilePath).Documents。

目前只使用了前5个参数, new Variant[] {Background, Append, Range;/*** * 将word文档打印为PS文件后,使用Distiller将PS文件转换为PDF文件 *** @param sourceFilePath* 源文件路径 ** @param destinPSFilePath* 首先生成的PS文件路径 ** @param destinPDFFilePath* 生成PDF文件路径*/.Variant;作为输出的pdf文档的路径Variant outputPDFFilePath = new Variant(destinPDFFilePath);//定义FileToPDF方法要使用adobe pdf设置文件的路径,在这里没有赋值表示并不使用pdf配置文件Variant PDFOption = new Variant("");//调用FileToPDF方法将ps文档转换为pdf文档Dispatch.callN(distiller, "FileToPDF", new Variant[] {inputPostScriptFilePath, outputPDFFilePath, PDFOption });System.out.println("由ps文档转换为pdf文档成功!");} catch (Exception ex) {ex.printStackTrace();} finally {closeWord();wordCom=null;//释放在程序线程中引用的其它com,比如Adobe PDFDistillerComThread.Release();}}public static void main(String[] argv) {D2P d2p = new D2P();d2p.docToPDF("d:/12.doc", "d:/1p.ps", "d:/1p.pdf");//这里是你建一个叫12.doc的word文档,生成的文档将在D盘下//1p.ps和1p.pdf(这是我们要的)}}.invoke(wrdDocs, &quot.invoke("Quit";设置当前使用的打印机,我的Adobe Distiller打印机名字为"/** */.1");try {///** */Open"public boolean openWord(String filePath) {///*** 关闭word文档*/public void closeWord() {///输出的postscript文件的路径Variant OutputFileName = new Variant(destinPSFilePath);public class D2P {private ActiveXComponent wordCom = null.jacob.Dispatch;import com, "PrintOut"需要用到插件jacob,自己去下载吧;//).println("打印所有文档int wdPrintAllDocument = 0;Variant Range = new Variant(wdPrintAllDocument);//*** 打开word文档** @param filePath* word文档* @return 返回word文档对象*//是否在后台运行Variant Background = False;/.out;/** *//** */import com.jacob.com.ComThread;import com。

import com.jacob.activeX.ActiveXComponent.Open方法打开指定的word文档, OutputFileName });System;Word.Application", new Variant("return true.toDispatch();//** */.com, new Variant[] {});}/** */Dispatch.callN((Dispatch) wordDoc.jacob,String destinPDFFilePath) {if (;由word文档打印为ps文档成功!");/public void docToPDF(String sourceFilePath, String destinPSFilePath;private Object wordDoc = null;/设置printout的参数,将word文档打印为postscript文档,如果要使用更多的话可以参考MSDN的office开发相关api/, Dispatch.Method,详细内容参考Distiller Api手册//返回wrdCom;private final Variant False = new Variant(false);private final Variant True = new Variant(true);建立ActiveX部件wordCom = new ActiveXComponent(&quot!openWord(sourceFilePath)) {closeWord();return;);关闭word文件wordCom;/调用Distiller对象的FileToPDF方法所用的参数;try {/} catch (Exception ex) {ex.printStackTrace();}return false;}/** *//调用wrdCom;/** */}/.com 展开

HTML文档标记匹配算法 要求:输入一段HTML代码,判断该代码是否...

ueditor实现word文档的导入和下载功能的方法:1、UEditor没有提供word的导入功能,只能说是粘贴复制。

2、方案:用poi来提供word导入,思路是将word转换为html输出,再用UEditor提供的setContent()方法将html的内容添加到编辑器中。

方案缺点,一是poi对word文本的格式获取必须按setContent()可接受的方式进行;二是我暂时没发现poi可以提供获取段落格式(对齐方式、缩进量)的方法。

代码如下:package demo;

上一篇:word里的图片怎么移动位置 word图片怎么调整

下一篇:word打断表格 word如何打断表格