网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.用Java调用VC音量控制程序.
.Java咖啡馆(3)——Eclipse.
.Jboss入门精简篇.
.互联网发展Web的未来是语义的.
.JXTA技术与应用发展慨述.
.Struts实现文件下载中文乱码解决.
.如何测定JDBC的性能(下).
.Hibernate 入门(1).
.在JAVA中使用文档对象模型DOM经验.
.java.util.List翻译.
.新手入门:介绍Java学习的一些主.
.在JAVA中连接Oracle数据库.
.教你如何编写Java类(一).
.破除java神话之垃圾收集解决所有.
.java读取配置文件例子.
.面向对象编程之:Java中的抽象数.
.J2EE表现层设计思考.
.Jive笔记--Database Package下面.
.《Java编程思想》(第二版)第6:重.
.触摸Java中的包和文档.

Java如何操作Word, Excel, PDF文档?

发表日期:2008-1-5


 

  参考:

  http://danadler.com/jacob/
  http://jakarta.apache.org/poi/
  http://www.onJava.com/pub/a/onjava/2003/01/22/poi.Html
  http://www.csdn.net/develop/article/15/15311.shtm
  http://forum.java.sun.com/thread.jsp?forum=40&thread=382666&tstart=0&trange=15

  Java Excel API 文档

  http://www.andykhan.com/jexcelapi/

  1、一个jacob操作Word的例子,其他操作excel,pdf的sample里都有

  import java.io.File;
  import com.jacob.com.*;
  import com.jacob.activeX.*;
  public class WordTest {
  
   public static void main(String[] args) {
     WordBean word=new WordBean();
     word.openWord(true);
     word.createNewDocument();
     word.insertText("Hello word.");
   }
  }

  import com.jacob.activeX.*;
  import com.jacob.com.*;
  public class WordBean extends java.awt.Panel
  {
   private ActiveXComponent MsWordApp = null;
   private Dispatch document = null;
   public WordBean()
   {
     super();
   }
   public void openWord(boolean makeVisible)
   {
  //Open Word if we've not done it already
     if (MsWordApp == null)
     {
       MsWordApp = new ActiveXComponent("Word.Application");
     }
  //Set the visible property as required.
     Dispatch.put(MsWordApp, "Visible",
            new Variant(makeVisible));
   }
   public void createNewDocument()
   {
  //Find the Documents collection object maintained by Word
     Dispatch documents =
         Dispatch.get(MsWordApp,"Documents").toDispatch();
  //Call the Add method of the Documents collection to create
  //a new document to edit
     document = Dispatch.call(documents,"Add").toDispatch();
   }
   public void insertText(String textToInsert)
   {
  // Get the current selection within Word at the moment. If
  // a new document has just been created then this will be at
  // the top of the new doc
     Dispatch selection =
         Dispatch.get(MsWordApp,"Selection").toDispatch();
  //Put the specified text at the insertion point
     Dispatch.put(selection,"Text",textToInsert);
   }
   public void saveFileAs(String filename)
   {
     Dispatch.call(document,"SaveAs",filename);
   }
   public void printFile()
   {
  //Just print the current document to the default printer
     Dispatch.call(document,"PrintOut");
   }
   public void closeDocument()
   {
  // Close the document without saving changes
  // 0 = wdDoNotSaveChanges
  // -1 = wdSaveChanges
  // -2 = wdPromptToSaveChanges
     Dispatch.call(document, "Close", new Variant(0));
     document = null;
   }
   public void closeWord()
   {
     Dispatch.call(MsWordApp,"Quit");
     MsWordApp = null;
     document = null;
   }
  }


上一篇:Spring2.0中新的Bean类型实现原理 人气:608
下一篇:Hibernate程序性能优化的考虑要点 人气:1293
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐