近來發現問這方面的問題特別多
Java操作PDF
Java操作Word
參考:
?forum=
一個jacob操作Word的例子
import java
import
import com
public class WordTest {
public static void main(String[] args) {
WordBean word=new WordBean();
word
word
word
}
}
import com
import
public class WordBean extends java
{
private ActiveXComponent MsWordApp = null;
private Dispatch document = null;
public WordBean()
{
super();
}
public void openWord(boolean makeVisible)
{
//Open Word if we
if (MsWordApp == null)
{
MsWordApp = new ActiveXComponent(
}
//Set the visible property as required
Dispatch
new Variant(makeVisible));
}
public void createNewDocument()
{
//Find the Documents collection object maintained by Word
Dispatch documents =
Dispatch
//Call the Add method of the Documents collection to create
//a new document to edit
document = Dispatch
}
public void insertText(String textToInsert)
{
// Get the current selection within Word at the moment
// a new document has just been created then this will be at
// the top of the new doc
Dispatch selection =
Dispatch
//Put the specified text at the insertion point
Dispatch
}
public void saveFileAs(String filename)
{
Dispatch
}
public void printFile()
{
//Just print the current document to the default printer
Dispatch
}
public void closeDocument()
{
// Close the document without saving changes
//
//
//
Dispatch
document = null;
}
public void closeWord()
{
Dispatch
MsWordApp = null;
document = null;
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26588.html