首頁 資料庫 mysql教程 Java操作Word,Excel,Access,IE,OutLook,PDF等

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

Jun 07, 2016 pm 03:11 PM
access excel java word 操作

近来发现问这方面的问题特别多,花了点时间,找了一些资料,并整理出一个简单例子 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/2

近来发现问这方面的问题特别多,花了点时间,找了一些资料,并整理出一个简单例子

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

一个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;

}

}
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

兩個點博物館:邦格荒地地點指南
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

兩個點博物館:邦格荒地地點指南
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Java 中的平方根 Java 中的平方根 Aug 30, 2024 pm 04:26 PM

Java 中的平方根

Java 中的完美數 Java 中的完美數 Aug 30, 2024 pm 04:28 PM

Java 中的完美數

Java 中的隨機數產生器 Java 中的隨機數產生器 Aug 30, 2024 pm 04:27 PM

Java 中的隨機數產生器

deepseek怎麼轉換pdf deepseek怎麼轉換pdf Feb 19, 2025 pm 05:24 PM

deepseek怎麼轉換pdf

Java 中的阿姆斯壯數 Java 中的阿姆斯壯數 Aug 30, 2024 pm 04:26 PM

Java 中的阿姆斯壯數

Java中的Weka Java中的Weka Aug 30, 2024 pm 04:28 PM

Java中的Weka

Java Spring 面試題 Java Spring 面試題 Aug 30, 2024 pm 04:29 PM

Java Spring 面試題

突破或從Java 8流返回? 突破或從Java 8流返回? Feb 07, 2025 pm 12:09 PM

突破或從Java 8流返回?

See all articles