如何在php下实现word转换成HTML,都进来看看吧
你好,试试我这个吧刚刚测试完的。
/* @author axgle 直接用php把word文档转化成HTML文件 适用于windows和安装了word的环境 */ function word2html($wfilepath) { $word=new COM("Word.Application") or die("无法打开 MS Word"); $word->visible = 1 ; $word->Documents->Open($wfilepath)or die("无法打开这个文件"); $htmlpath= substr($wfilepath,0,-4); $word->ActiveDocument->SaveAs($htmlpath,8); $word->quit(0); } $w="G:/www/test.doc"; word2html($w); print( "Word转html完成!" ); ?>
如何使用php将html页面转为word文档
具体的需要将html页面转为word文档。
尝试使用了设置Content-Type:application/msword的方法,可以保存。
希望能帮到你,我还要抓紧时间自己在后盾人平台自己学习呢,一起希望加油吧≡ ∧_∧ ∧_∧ ≡(#`Д′)? ;;;)Д`)≡/つ / ? ?/
php关于html模板导入word显示问题
如果你用IIS(不一定要7)的话是可以多个进程的,看下下面的帖子吧。
如果是IIS5或6先装下这个。
http://www.iis.net/download/fastcgi 具体配置看下面的文章。
http://learn.iis.net/page.aspx/248/configuring-the-fastcgi-extension-for-iis-60/ http://learn.iis.net/page.aspx/247/using-fastcgi-to-host-php-applications-on-iis-60/
如何利用openoffice读取word文档,并输出在页面上(HTML)
将Word转Html的原理是这样的:1、客户上传Word文档到服务器2、服务器调用OpenOffice程序打开上传的Word文档3、OpenOffice将Word文档另存为Html格式4、Over至此可见,这要求服务器端安装OpenOffice软件,其实也可以是MS Office,不过OpenOffice的优势是跨平台,你懂的。
恩,说明一下,本文的测试基于 MS Win7 Ultimate X64 系统。
下面就是规规矩矩的实现。
1、下载OpenOffice,2、下载Jodconverter 这是一个开启OpenOffice进行格式转化的第三方jar包。
3、泡杯热茶,等待下载。
4、安装OpenOffice,安装结束后,调用cmd,启动OpenOffice的一项服务:C:\Program Files (x86)\OpenOffice.org 3\program>soffice -headless -accept="socket,port=8100;urp;"5、打开eclipse6、喝杯热茶,等待eclipse打开。
7、新建eclipse项目,导入Jodconverter/lib 下得jar包。
* commons-io * jodconverter * juh * jurt * ridl * slf4j-api * slf4j-jdk14 * unoil * xstream 8、Coding...查看代码package com.mzule.doc2html.util;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStreamReader;import java.net.ConnectException;import java.util.Date;import java.util.regex.Matcher;import java.util.regex.Pattern;import com.artofsolving.jodconverter.DocumentConverter;import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;/** * 将Word文档转换成html字符串的工具类 * * @author MZULE * */public class Doc2Html { public static void main(String[] args) { System.out .println(toHtmlString(new File("C:/test/test.doc"), "C:/test")); } /** * 将word文档转换成html文档 * * @param docFile * 需要转换的word文档 * @param filepath * 转换之后html的存放路径 * @return 转换之后的html文件 */ public static File convert(File docFile, String filepath) { // 创建保存html的文件 File htmlFile = new File(filepath + "/" + new Date().getTime() + ".html"); // 创建Openoffice连接 OpenOfficeConnection con = new SocketOpenOfficeConnection(8100); try { // 连接 con.connect(); } catch (ConnectException e) { System.out.println("获取OpenOffice连接失败..."); e.printStackTrace(); } // 创建转换器 DocumentConverter converter = new OpenOfficeDocumentConverter(con); // 转换文档问html converter.convert(docFile, htmlFile); // 关闭openoffice连接 con.disconnect(); return htmlFile; } /** * 将word转换成html文件,并且获取html文件代码。
* * @param docFile * 需要转换的文档 * @param filepath * 文档中图片的保存位置 * @return 转换成功的html代码 */ public static String toHtmlString(File docFile, String filepath) { // 转换word文档 File htmlFile = convert(docFile, filepath); // 获取html文件流 StringBuffer htmlSb = new StringBuffer(); try { BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(htmlFile))); while (br.ready()) { htmlSb.append(br.readLine()); } br.close(); // 删除临时文件 htmlFile.delete(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // HTML文件字符串 String htmlStr = htmlSb.toString(); // 返回经过清洁的html文本 return clearFormat(htmlStr, filepath); } /** * 清除一些不需要的html标记 * * @param htmlStr * 带有复杂html标记的html语句 * @return 去除了不需要html标记的语句 */ protected static String clearFormat(String htmlStr, String docImgPath) { // 获取body内容的正则 String bodyReg = ""; Pattern bodyPattern = Pattern.compile(bodyReg); Matcher bodyMatcher = bodyPattern.matcher(htmlStr); if (bodyMatcher.find()) { // 获取BODY内容,并转化BODY标签为DIV htmlStr = bodyMatcher.group().replaceFirst("", ""); } // 调整图片地址 htmlStr = htmlStr.replaceAll("转换成保留样式 // content = content.replaceAll("(]*>.*?)()", // ""); // 把转换成并删除样式 htmlStr = htmlStr.replaceAll("(]*)(>.*?)()", ""); // 删除不需要的标签 htmlStr = htmlStr .replaceAll( "]*?>", ""); // 删除不需要的属性 htmlStr = htmlStr .replaceAll( "]*)(?:lang|LANG|class|CLASS|style|STYLE|size|SIZE|face|FACE|[ovwxpOVWXP]:\\w+)=(?:'[^']*'|\"\"[^\"\"]*\"\"|[^>]+)([^>]*)>", ""); return htmlStr; }}
DW 怎么把css文件转换HTML
你是想把单独的CSS文件合并到HTML文件内吗?在HTML页面内直接加入CSS样式代码? 本人不建议这样做,因为不利于网站seo,为给网站带来一定负担。
1,外联式样式表;2,内嵌样式表; p{font:12px;color:red}--> 3,元素内定; 4,导入样式表 @import url(css/index.css); --> ...
怎么把php代码转成html代码
php代码转换成HTML??不是一种东西,用途也不一样如何转换,就像一个人如何转换成一头猪? 物种不同但一个男人可以转换成一个女人,可以去做变性手术嘛~,物种相同就可以转换PHP是后端脚本语言HTML是前端页面语言PHP可以输出HTML ,但没有办法将PHP转换成HTML...
poi的word转html,如何显示修订内容的最终状态
实现代码如下: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); } }
转载请注明出处51数据库 » php cgi word转html?