java对word、excel、pdf等操作综合文章

文章作者 100test 发表时间 2007:03:14 16:24:13
来源 100Test.Com百考试题网


Java操作PDF http://www.lowagie.com/
Java操作Word,Excel,Access
参考:
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 weve 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 0selection 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 0selection =
         Dispatch.get(MsWordApp,"Selection").toDispatch().
  //Put the specified text at the insertion point
     Dispatch.put(0selection,"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.
   }
  }


相关文章


Java2下Applet数字签名具体实现方法
java对word、excel、pdf等操作综合文章
用java的jwindow运行出的splash画面
int和String互相转换的多种方法
邮箱页面中“删除”和“永久删除”的实现
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛