jsp怎样操作word.docVIP

  • 2
  • 0
  • 约2.35千字
  • 约 3页
  • 2017-07-31 发布于河南
  • 举报
jsp怎样操作word

jsp 怎样操作 word 各位大哥大姐们,请问怎样用java 操作word文档 ,向word中添加图片、表格,并且从word中读取所有内容(包括文字、图片和表格)? 我找了很长时间也没找到可行的方法。有谁会呀,请赐教,谢了!!!jacob帮你完成. Java code 一个jacob操作Word的例子,其他操作excel,pdf的sample里都有   import java.io.File;   import .*;   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 .*;   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 weve 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()    {   //

文档评论(0)

1亿VIP精品文档

相关文档