JavaExcelAPI文档http://www。andykhan。com/jexcelapi/1、一个jacob操作Word的例子,其他操作excel,pdf的sample里都有importjava。io。File;importcom。 jacob。com。*;importcom。jacob。activeX。*;publicclassWordTest{publicstaticvoidmain(String[]args){WordBeanword=newWordBean();word。 openWord(true);word。createNewDocument();word。insertText("Helloword。");}}importcom。jacob。activeX。*;importcom。 jacob。com。*;publicclassWordBeanextendsjava。awt。Panel{privateActiveXComponentMsWordApp=null;privateDispatchdocument=null;publicWordBean(){super();}publicvoidopenWord(booleanmakeVisible){//OpenWordifwe'venotdoneitalreadyif(MsWordApp==null){MsWordApp=newActiveXComponent("Word。 Application");}//Setthevisiblepropertyasrequired。Dispatch。put(MsWordApp,"Visible",newVariant(makeVisible));}publicvoidcreateNewDocument(){//FindtheDocumentscollectionobjectmaintainedbyWordDispatchdocuments=Dispatch。 get(MsWordApp,"Documents")。toDispatch();//CalltheAddmethodoftheDocumentscollectiontocreate//anewdocumenttoeditdocument=Dispatch。 call(documents,"Add")。toDispatch();}publicvoidinsertText(StringtextToInsert){//GetthecurrentselectionwithinWordatthemoment。 If//anewdocumenthasjustbeencreatedthenthiswillbeat//thetopofthenewdocDispatchselection=Dispatch。 get(MsWordApp,"Selection")。toDispatch();//PutthespecifiedtextattheinsertionpointDispatch。put(selection,"Text",textToInsert);}publicvoidsaveFileAs(Stringfilename){Dispatch。 call(document,"SaveAs",filename);}publicvoidprintFile(){//JustprintthecurrentdocumenttothedefaultprinterDispatch。 call(document,"PrintOut");}publicvoidcloseDocument(){//Closethedocumentwithoutsavingchanges//0=wdDoNotSaveChanges//-1=wdSaveChanges//-2=wdPromptToSaveChangesDispatch。 call(document,"Close",newVariant(0));document=null;}publicvoidcloseWord(){Dispatch。call(MsWordApp,"Quit");MsWordApp=null;document=null;}}。
阅读全文 >