用java程序读word文档 RT,如何用java写一个程序验证word文档是否满足某种格式,比如标题是哪种字体,大小 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用jacob:只能是windows系统使用, 下载zip包,解压,得到一个jar和一个dll,jar导入到项目,dll放到C:\WINDOWS\system32目录下 import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch; import com.jacob.com.Variant; public class TestWord{ public static void main(String[] args){ System.out.println(ChageFormat("c:\\","test.doc")); } public static boolean ChageFormat (String FolderPath,String FileName){ String FileFormat = ""; System.out.println(FolderPath); FileFormat = FileName.substring(FileName.length()-4,FileName.length()); System.out.println(FileFormat); if(FileFormat.equalsIgnoreCase(".doc")) { String DocFile = FolderPath +"\\"+ FileName; System.out.println("word文件路径:"+DocFile); //word文件的完整路径 String HtmlFile = DocFile.substring(0, (DocFile.length() - 4)) + ".txt";//要是用htm的,把这里改成.htm System.out.println("htm文件路径:"+HtmlFile); //html文件的完整路径 ActiveXComponent app = new ActiveXComponent("Word.Application"); //启动word try { app.setProperty("Visible", new Variant(false)); //设置word程序非可视化运行 Dispatch docs = app.getProperty("Documents").toDispatch(); Dispatch doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{DocFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch(); //打开word文件 Dispatch.invoke(doc,"SaveAs",Dispatch.Method, new Object[]{HtmlFile,new Variant(7)}, new int[1]);//需奥生成htm的话,改成 new Variant(8),把上面的.txt,改成.htm //作为htm格式保存文件 Dispatch.call(doc, "Close",new Variant(false)); //关闭文件 } catch (Exception e) { e.printStackTrace(); } finally { app.invoke("Quit", new Variant[] {}); //退出word程序 } //转化完毕 return true; } return false; } } 二楼的正解,但是你的DLL文件得注册 struts2集成fckeditor 复制出问题 jsp登录界面要怎么写 小妹请教一个问题 我用resin,jboss,tomcat+mysql服务器运行网站遇到的问题! 问一个<bean:write>的问题!! DES加密解密 大家好,我今天开始学JAVA,但是... 两个工程,怎么互相引用啊,在线等。。。 关于java编码和JDBC字符转换的问题,请大家帮忙! 公交查询系统的 数据 怎么来? DWR怎么传流总是转换出错??高手速度解!!! JAVA中code segment,data segment,heap,stack分别存放什么内容?
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TestWord{
public static void main(String[] args){
System.out.println(ChageFormat("c:\\","test.doc"));
}
public static boolean ChageFormat (String FolderPath,String FileName){
String FileFormat = "";
System.out.println(FolderPath);
FileFormat = FileName.substring(FileName.length()-4,FileName.length());
System.out.println(FileFormat);
if(FileFormat.equalsIgnoreCase(".doc"))
{
String DocFile = FolderPath +"\\"+ FileName;
System.out.println("word文件路径:"+DocFile);
//word文件的完整路径
String HtmlFile = DocFile.substring(0, (DocFile.length() - 4)) + ".txt";//要是用htm的,把这里改成.htm
System.out.println("htm文件路径:"+HtmlFile);
//html文件的完整路径
ActiveXComponent app = new ActiveXComponent("Word.Application");
//启动word
try
{
app.setProperty("Visible", new Variant(false));
//设置word程序非可视化运行
Dispatch docs = app.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{DocFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();
//打开word文件
Dispatch.invoke(doc,"SaveAs",Dispatch.Method, new Object[]{HtmlFile,new Variant(7)}, new int[1]);//需奥生成htm的话,改成 new Variant(8),把上面的.txt,改成.htm
//作为htm格式保存文件
Dispatch.call(doc, "Close",new Variant(false));
//关闭文件
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
//退出word程序
}
//转化完毕
return true;
}
return false;
}
}