Java操作Word,Excel,Access,IE,OutLook,PDF等
近来发现问这方面的问题特别多,花了点时间,找了一些资料,并整理出一个简单例子 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;
}
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

Laravel框架中Redis连接的共享与select方法的影响在使用Laravel框架和Redis时,开发者可能会遇到一个问题:通过配置...

多线程的好处在于能提升性能和资源利用率,尤其适用于处理大量数据或执行耗时操作。它允许同时执行多个任务,提高效率。然而,线程过多会导致性能下降,因此需要根据 CPU 核心数和任务特性谨慎选择线程数。另外,多线程编程涉及死锁和竞态条件等挑战,需要使用同步机制解决,需要具备扎实的并发编程知识,权衡利弊并谨慎使用。

Node环境下如何避免第三方接口返回403错误在使用Node.js调用第三方网站接口时,有时会遇到返回403错误的问题。�...

无法以 root 身份登录 MySQL 的原因主要在于权限问题、配置文件错误、密码不符、socket 文件问题或防火墙拦截。解决方法包括:检查配置文件中 bind-address 参数是否正确配置。查看 root 用户权限是否被修改或删除,并进行重置。验证密码是否准确无误,包括大小写和特殊字符。检查 socket 文件权限设置和路径。检查防火墙是否阻止了 MySQL 服务器的连接。

SQL IF 语句用于有条件地执行 SQL 语句,语法为: IF (condition) THEN {语句} ELSE {语句} END IF;。条件可以是任何有效的 SQL 表达式,如果条件为真,执行 THEN 子句;如果条件为假,执行 ELSE 子句。IF 语句可以嵌套,允许更复杂的条件检查。

PHP和Python各有优势,选择应基于项目需求。1.PHP适合web开发,语法简单,执行效率高。2.Python适用于数据科学和机器学习,语法简洁,库丰富。

在EasyWechat5.5中获取ComponentVerify...

PHP中如何有效处理token的缓存问题?在使用PHP开发的项目中,我们常常需要处理和管理token,特别是在与微信API�...
