国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Java操作Word,Excel,Access,IE,OutLook, PDF 等

2019-11-18 12:09:00
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

  近來(lái)發(fā)現(xiàn)問(wèn)這方面的問(wèn)題非凡多,花了點(diǎn)時(shí)間,找了一些資料,并整理出一個(gè)簡(jiǎn)單例子
  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
  
  一個(gè)jacob操作Word的例子,操作Excel,Access,Outlook的例子jacob的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;
   }
  }

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 承德市| 朝阳市| 清远市| 治县。| 叙永县| 乌兰县| 城口县| 阿拉善盟| 台江县| 麦盖提县| 玉树县| 开江县| 上饶市| 临城县| 乌苏市| 桐梓县| 楚雄市| 鸡西市| 彰化市| 化德县| 溧阳市| 广河县| 太原市| 太白县| 共和县| 红原县| 开化县| 郁南县| 怀宁县| 虹口区| 平谷区| 北流市| 阳曲县| 罗山县| 凤城市| 石城县| 盐边县| 恩平市| 遵义县| 新安县| 隆回县|