永中Office二次開發_JAVA的二次開發2

來源:互聯網
上載者:User

概述:永中Office是使用JAVA開發,所以直接使用JAVA進行二次開發比較方便,但由於在用戶端運行時一般使用VB、VC去調用,所以有必要將其封裝成COM組件,以便其它語言調用。

 

今天繼續先將JAVA的二次開發的第二部分調用執行個體進行說明:

 

(如果大家覺得好我就繼續,如果覺得不好這第二篇文章就算結束了)

 

1.清除痕迹

public static boolean AcceptAllRevision(Document document)<br />{<br />document.acceptAllRevision();<br />return true;<br />}

2.在書籤位置插入圖片

public static boolean InsertPicToBookmark(Document document, String bookMarkName, String picPath, float width, float height)<br />{<br />BookMark bk = document.getBookmarks().get(bookMarkName);<br />if(bk == null)<br />return false;</p><p>InsertPicToTextRange(bk.getRange(), picPath, width, height, true);</p><p>return true;<br />}

3.在RANGE位置插入圖片

public static boolean InsertPicToTextRange(TextRange range, String picPath, float width, float height, boolean isBefore)<br />{<br />if(width*height == 0)<br />{<br />if(isBefore)<br />range.insertPictureBefore(picPath);<br />else<br />range.insertPictureAfter(picPath);<br />}<br />else<br />{<br />if(isBefore)<br />range.insertPictureBefore(picPath, width, height);<br />else<br />range.insertPictureAfter(picPath, width, height);<br />}</p><p>return true;<br />}

4.書籤位置插入檔案

public static boolean InsertFileToBookmark(Document document, String bookMarkName, String filePath)<br />{<br />String t = filePath.toLowerCase();<br />if(!(t.contains(".doc") || t.contains(".rtf") || t.contains(".eio") || t.contains(".eit") || t.contains(".txt")))<br />return false;<br />BookMark bk = document.getBookmarks().get(bookMarkName);<br />if(bk == null)<br />return false;</p><p>document.setOffset(bk.getEndPosition());<br />document.insertDocument(2, filePath, null);</p><p>return true;<br />}<br />

5.RANGE位置插入檔案

public static boolean InsertFileToTextRange(Document document, TextRange range, String filePath)<br />{<br />String t = filePath.toLowerCase();<br />if(!(t.contains(".doc") || t.contains(".rtf") || t.contains(".eio") || t.contains(".eit") || t.contains(".txt")))<br />return false;<br />if(range==null)<br />return false;<br />document.setOffset(range.getEndOffset());<br />document.insertDocument(2, filePath, null);<br />return true;<br />}

6.插入表格

public static boolean InsertTableToDocument(Document document, TextRange range, String tableName, int rowCount, int columnCount)<br />{<br />if(range == null)<br />return false;</p><p>document.getTables().addTable(range, rowCount, columnCount, tableName, TableConstants.AUTOFIT_CONTENT, 0);</p><p>return true;<br />}

7.保護、解保護文檔

public static boolean ProtectDocument(Document document, int protectType)<br />{<br />document.protect(protectType, DOCPASSWORD);<br />return true;<br />}</p><p>public static boolean UnprotectDocument(Document document)<br />{<br />document.unprotect(DOCPASSWORD);<br />return true;<br />}<br />

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.