java操作word文档
来源:互联网 发布:tk免费域名 编辑:程序博客网 时间:2024/05/08 06:38
1、一个jacob操作Word的例子,其他操作excel,pdf的sample里都有,可以作为java资料进行保留
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;
}
}
- java操作word文档
- JAVA操作WORD文档
- java操作word文档
- java操作word文档
- POI-JAVA操作WORD文档
- Java如何操作Word, Excel, PDF文档
- Java如何操作Word, Excel, PDF文档
- Java如何操作Word, Excel, PDF文档
- 如何利用Java-JACOB操作WORD文档
- 如何利用Java-JACOB操作WORD文档
- Java如何操作Word, Excel, PDF文档?
- Java如何操作Word, Excel, PDF文档?
- Java操作MS Word和Excel文档
- Java操作Word文档封装类
- 利用Java-JACOB操作WORD文档2
- 利用Java-JACOB操作WORD文档2
- 利用Java-JACOB操作WORD文档2
- 如何利用Java-JACOB操作WORD文档
- javascript
- Web Handler 文件 ashx
- 纯CSS画的基本图形(矩形、圆形、三角形、多边形、爱心、八卦等)很不错哟~~
- mysql通过触发器实现两个表的同步
- Oracle常见面试题
- java操作word文档
- 20121113-1602液晶测试程序2
- 006_函数的3种创建方式和区别
- Linux 开发环境工具 下载网址大全
- js的高级复习
- QWaitCondition类
- assert宏 (基本概念与用法整理)
- linux uniq 命令介绍
- 设计模式(一)Strategy - 策略模式