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

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

java對word、excel、pdf等操作綜合文章

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


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

2、 Java Excel 操作excel
 從Excel文件讀取數據表

Java Excel API既可以從本地文件系統的一個文件(.xls),也可以從輸入流中讀取Excel數據表。讀取Excel數據表的第一步是創建Workbook(術 語:工作薄),下面的代碼片段舉例說明了應該如何操作:(完整代碼見ExcelReading.java)


import java.io.*;
import jxl.*;
… … … …
try
{
//構建Workbook對象, 只讀Workbook對象
//直接從本地文件創建Workbook
//從輸入流創建Workbook
    InputStream is = new FileInputStream(sourcefile);
    jxl.Workbook rwb = Workbook.getWorkbook(is);
}
catch (Exception e)
{
e.printStackTrace();
}




發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍林郭勒市| 肥乡县| 黄梅县| 仙居县| 德保县| 扎赉特旗| 招远市| 宁德市| 内乡县| 沙洋县| 吉木萨尔县| 晴隆县| 壶关县| 都安| 通辽市| 鹤壁市| 钟山县| 海口市| 额尔古纳市| 汉源县| 平武县| 靖远县| 扶风县| 宣汉县| 五常市| 太谷县| 仪陇县| 乌海市| 西林县| 樟树市| 云龙县| 张家港市| 永平县| 山西省| 克山县| 克拉玛依市| 河北省| 讷河市| 上高县| 当涂县| 措勤县|