隨筆-48  評論-26  文章-0  trackbacks-0


          ActiveXComponent word = new ActiveXComponent("Word.Application");
           word.setProperty(
          "Visible"new Variant(false));
          /***************************************************************************
               * 刪除書簽
               * 
               * 
          @param mark  書簽名
               * 
          @param info  可替換
               * 
          @return
               
          */
              
          public boolean deleteBookMark(String markKey, String info) throws Exception{
                  Dispatch activeDocument 
          = word.getProperty("ActiveDocument")
                          .toDispatch();
                  Dispatch bookMarks 
          = word.call(activeDocument, "Bookmarks")
                          .toDispatch();
                  
          boolean isExists = word.call(bookMarks, "Exists", markKey)
                          .toBoolean();
                  
          if (isExists) {
                      
                      Dispatch n 
          = Dispatch.call(bookMarks, "Item", markKey).toDispatch();
                      Dispatch.call(n, 
          "Delete");
                      
                      
          return true;
                  } 
                  
          return false;
              }
          /***************************************************************************
               * 根據書簽插入數據
               * 
               * 
          @param bookMarkKey 書簽名
               * 
          @param info  插入的數據
               * 
          @return
               
          */
            
              
          public boolean intoValueBookMark(String bookMarkKey, String info) throws Exception{
                         
                  Dispatch activeDocument 
          = word.getProperty("ActiveDocument")
                          .toDispatch();
                  Dispatch bookMarks 
          = word.call(activeDocument, "Bookmarks")
                          .toDispatch();
                  
          boolean bookMarkExist = word.call(bookMarks, "Exists", bookMarkKey)
                          .toBoolean();
                  
          if (bookMarkExist) {
                      
                      Dispatch rangeItem 
          = Dispatch.call(bookMarks, "Item", bookMarkKey)
                              .toDispatch();
                      Dispatch range 
          = Dispatch.call(rangeItem, "Range").toDispatch();
                      Dispatch.put(range, 
          "Text"new Variant(info));
                      
          return true;
                  } 
                  
          return false;
              }

          posted on 2009-12-08 17:30 Worker 閱讀(2493) 評論(3)  編輯  收藏 所屬分類: J2SE/J2EE

          評論:
          # re: Jacob操作Word書簽 2011-09-19 16:35 | asfd
          alert();  回復  更多評論
            
          # re: Jacob操作Word書簽 2011-09-19 16:37 | asfd
          <script>alert();</script>  回復  更多評論
            
          # re: Jacob操作Word書簽 2015-03-17 17:10 | ss
          如何替換書簽處上次插入的文本?  回復  更多評論
            
          <2015年3月>
          22232425262728
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(1)

          我參與的團隊

          隨筆分類(47)

          隨筆檔案(48)

          Forum

          Fun

          Study

          Util

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜


          主站蜘蛛池模板: 金塔县| 南宫市| 淮北市| 大邑县| 美姑县| 澳门| 贵港市| 广元市| 南皮县| 大英县| 清涧县| 碌曲县| 乌兰察布市| 威远县| 通海县| 盐亭县| 将乐县| 禹城市| 日照市| 合肥市| 黑龙江省| 萝北县| 黔西| 华池县| 高青县| 凉城县| 城固县| 绥化市| 梁平县| 新民市| 始兴县| 密云县| 文登市| 阿坝县| 焉耆| 封开县| 师宗县| 基隆市| 德惠市| 灌云县| 青州市|