zoukankan      html  css  js  c++  java
  • java jacob 简易输出内容到Word中。。。

    1,首先需要下载jacob包http://sourceforge.net/projects/jacob-project/ ,并将jar放入lib包下,将对应系统的dll放入System32文件夹下,如果配置后的运行显示错误,可尝试下载jacob 1.11版本的包

    2,java代码片段

     1 ActiveXComponent MsWordApp = new ActiveXComponent("Word.Application"); 
    2 Dispatch.put(MsWordApp, "Visible",new Variant(true));
    3 Dispatch documents =Dispatch.get(MsWordApp,"Documents").toDispatch();
    4 Dispatch document = Dispatch.call(documents,"Add").toDispatch();
    5
    6 Dispatch selection = Dispatch.get(MsWordApp,"Selection").toDispatch();
    7 Dispatch.put(selection,"Text","要插入的内容");
    8 String path = request.getSession().getServletContext().getRealPath("\\")+"words\\";
    9 File f=new File(path);
    10 if(!f.exists()){
    11 f.mkdirs();
    12 }
    13 Dispatch.call(document,"SaveAs",path+System.currentTimeMillis());
    14 Dispatch.call(document, "Close", new Variant(0));
    15 Dispatch.call(MsWordApp,"Quit");
    16 MsWordApp = null;
    17 document = null;



    Author:Pale Life
    From: 
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    hdu1066之数学题
    hdu1065计算几何
    hdu1060
    hdu1056
    appium安装说明
    LR安装说明
    网络编程
    读写excel
    dom
    HTML
  • 原文地址:https://www.cnblogs.com/live365wang/p/2417636.html
Copyright © 2011-2022 走看看