麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

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

2019-11-18 13:34:08
字體:
來源:轉載
供稿:網友

 

  參考:

  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;
   }
  }



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲第一黄色网 | 国产日韩大片 | 男女羞羞视频 | 黄色影院网站 | 特大黑人videos与另类娇小 | 香蕉久久久久 | 亚洲热线99精品视频 | 毛片大全在线观看 | 亚洲精品午夜电影 | 亚洲网站一区 | 亚洲一区二区三区在线免费观看 | 无码av女优 | 国产精品久久久久久婷婷天堂 | 欧美日韩在线播放 | 九九精品在线观看视频 | 精品一区二区久久久久久按摩 | 久久综合网址 | 国产91亚洲精品一区二区三区 | 一级黄色性感片 | 日本a∨精品中文字幕在线 欧美1—12sexvideos | 免费观看一区二区三区 | 国产又白又嫩又紧又爽18p | 91av爱爱| 日本在线一区二区 | 福利在线国产 | 精品黑人一区二区三区国语馆 | 久久无 | 日本一区视频在线观看 | 国产免费v片 | 成人 精品| 中国hdxxxx护士爽在线观看 | 成年免费大片黄在线观看岛国 | 欧美福利视频一区二区三区 | 黄色大片在线观看 | xnxx 美女19| h视频在线播放 | 成年人免费高清视频 | 国产毛片毛片 | 看片一区 | 午夜神马福利视频 | av日韩在线免费观看 |