最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 正文

java生成word文档

来源:动视网 责编:小OO 时间:2025-10-02 01:02:44
文档

java生成word文档

java生成word文档先下载jacob并把里面的jacob.jar加入到classpath中把jacob.dll放入windows/system32下面放入到path中点击我的电脑、属性、高级、系统变量jacob操作Word的例子importjava.io.File;importcom.jacob.com.*;importcom.jacob.activeX.*;publicclassWordTest{publicstaticvoidmain(String[]args){WordBeanwor
推荐度:
导读java生成word文档先下载jacob并把里面的jacob.jar加入到classpath中把jacob.dll放入windows/system32下面放入到path中点击我的电脑、属性、高级、系统变量jacob操作Word的例子importjava.io.File;importcom.jacob.com.*;importcom.jacob.activeX.*;publicclassWordTest{publicstaticvoidmain(String[]args){WordBeanwor
java生成word文档

先下载jacob并把里面的jacob.jar加入到classpath中

把jacob.dll放入windows/system32下面放入到path中点击我的电脑、属性、高级、系统变量

jacob操作Word的例子

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.");

}

}

以下是WordBean类

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

}

public void saveFileAs(String filename)

{

Dispatch.call(document,"SaveAs

}

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

document = null;

}

public void closeWord()

{

Dispatch.call(MsWordApp,"Quit");

MsWordApp = null;

document = null;

}

}

文档

java生成word文档

java生成word文档先下载jacob并把里面的jacob.jar加入到classpath中把jacob.dll放入windows/system32下面放入到path中点击我的电脑、属性、高级、系统变量jacob操作Word的例子importjava.io.File;importcom.jacob.com.*;importcom.jacob.activeX.*;publicclassWordTest{publicstaticvoidmain(String[]args){WordBeanwor
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top