- ·上一篇:怎么写word代码
- ·下一篇:word文档白线怎么取消
怎么在网页中word文档
1.怎样将网页上的表格下载下来
1、首先,我们把该数据表格所在网页的URL地址复制下来。
2、然后在Excel中选择“数据”—获取外部数据中的”自网站“菜单项,此时会弹出“新建web查询”对话框。
3、将复制的URL地址粘贴到“新建web查询”的地址栏中,然后点击转到,就会出现相应的数据页面。
4、将鼠标移动到对话框里网页表格的左上角,我们将会看到左上角出现一个黄底黑色的箭头标志,它表示Excel已经识别此网页上的表格,我们点击一下箭头,箭头会变成绿色对号,提示选择表格成功,最后点击下面的“导入”。
5、在弹出的对话框中,我们可以选择默认设置,或者选择“属性”对其进行设置,最后点击“确定”即可,Excel将为我们获取数据。
6、导入数据过程中需要等待,根据网络情况和文件大小时间长短不同。
7、网页中的数据成功导入Excel表格中,然后我们可以根据自己的需要对数据进行处理。
2.怎么在网页中打开word文档.用代码实现
将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.; import com.artofsolving.jodconverter.openoffice.converter.;/** * 将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 (8100); try { // 连接 con.connect(); } catch (ConnectException e) { System.out.println("获取OpenOffice连接失败。
"); e.printStackTrace(); } // 创建转换器 DocumentConverter converter = new (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 = "<body .*