您好,欢迎访问一九零五行业门户网

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/2003
近来发现问这方面的问题非凡多,花了点时间,找了一些资料,并整理出一个简单例子
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;
 }
}
其它类似信息

推荐信息