数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

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


发布日期:2021年01月20日
 
Java操作Word,Excel,Access,IE,OutLook, PDF 等

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

Java操作PDF

Java操作WordExcelAccess

参考:

?forum=&thread=&tstart=&trange=

一个jacob操作Word的例子操作ExcelAccessOutlook的例子jacob的sample目录中有

import javaioFile;

import *;

import comjacobactiveX*;

public class WordTest {

public static void main(String[] args) {

WordBean word=new WordBean();

wordopenWord(true);

wordcreateNewDocument();

wordinsertText(Hello word);

}

}

import comjacobactiveX*;

import *;

public class WordBean extends javaawtPanel

{

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(WordApplication);

}

//Set the visible property as required

Dispatchput(MsWordApp Visible

new Variant(makeVisible));

}

public void createNewDocument()

{

//Find the Documents collection object maintained by Word

Dispatch documents =

Dispatchget(MsWordAppDocuments)toDispatch();

//Call the Add method of the Documents collection to create

//a new document to edit

document = Dispatchcall(documentsAdd)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 =

Dispatchget(MsWordAppSelection)toDispatch();

//Put the specified text at the insertion point

Dispatchput(selectionTexttextToInsert);

}

public void saveFileAs(String filename)

{

Dispatchcall(documentSaveAsfilename);

}

public void printFile()

{

//Just print the current document to the default printer

Dispatchcall(documentPrintOut);

}

public void closeDocument()

{

// Close the document without saving changes

// = wdDoNotSaveChanges

// = wdSaveChanges

// = wdPromptToSaveChanges

Dispatchcall(document Close new Variant());

document = null;

}

public void closeWord()

{

Dispatchcall(MsWordAppQuit);

MsWordApp = null;

document = null;

}

}

               

上一篇:Groovy入门—Grails实战之遗留数据库处理

下一篇:Sun力推JDS数据库计划 开拓数据库疆土