zoukankan      html  css  js  c++  java
  • jacob如何获取word文档的页码

    ActiveXComponent app = new ActiveXComponent("Word.Application"); //启动word
    String inFile = "C:\TEMP\test.doc"; 

    app.setProperty("Visible", new Variant(false)); //设置word不可见
    Dispatch docs = app.getProperty("Documents").toDispatch();
    Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,
    new Object[] { inFile, new Variant(false),new Variant(false) }, new int[1]).toDispatch();

    /*方法1: 通过查找文本取页码*/
    Dispatch selection = app.getProperty("Selection").toDispatch();//获得对Selection组件
    Dispatch.call(selection, "HomeKey", new Variant(6));//移到开头
    Dispatch find = Dispatch.call(selection, "Find").toDispatch();//获得Find组件
    Dispatch.put(find, "Text", "二、成果简介"); //查找字符串"二、成果简介"
    Dispatch.call(find, "Execute"); //执行查询

     String pages = Dispatch.call(selection, "Information",new Variant(3)).toString();

    System.out.println("文本所在页码:"+startpages);

    /*方法2: 通过查找书签取页码*/
    Dispatch bookMarks=Dispatch.call(doc,"Bookmarks").toDispatch();
    boolean bookMarkExist=Dispatch.call(bookMarks,"Exists","mark3").toBoolean();
    if(bookMarkExist){
    Dispatch rangeItem=Dispatch.call(bookMarks,"Item","mark3").toDispatch();
    Dispatch range=Dispatch.call(rangeItem,"Range").toDispatch();
    String markpage = Dispatch.call(range, "Information",new Variant(3)).toString();
    System.out.println("bookmark page:"+endpages);
    }

  • 相关阅读:
    IIS7用进程池的PID查找占用CPU的站点
    CSS中属性的书写顺序
    int[] 和 string[] 互换
    csv 文件的读取
    扩展 DataGridView 的功能(三)
    [音乐] the dream catcher
    雷人的面试
    将MP3文件嵌入到exe中并播放
    扩展 DataGridView 的功能(二)
    扩展DataGridView 的功能(四)
  • 原文地址:https://www.cnblogs.com/janehlp/p/3892678.html
Copyright © 2011-2022 走看看