[原創]java在線比較兩個word文件


一、項目背景

  開發文檔管理系統或OA辦公系統的時候,實現在線處理word文檔的功能比較容易,但是也經常會有客戶提出文檔版本管理的需求,這就需要同時在線打開兩個word文件,對比兩個不同版本的word文檔內容,在網上幾乎找不到解決方案。

二、解決方案

  集成PageOffice實現在線處理word文件,調用PageOffice的兩個word文檔對比的功能即可解決此問題,並且調用方法非常簡單:

  Java后台代碼:

  

PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
poCtrl1.setServerPage(request.getContextPath()+"/poserver.zz");

// Create custom toolbar
poCtrl1.addCustomToolButton("保存", "SaveDocument()", 1);
poCtrl1.addCustomToolButton("顯示A文檔", "ShowFile1View()", 0);
poCtrl1.addCustomToolButton("顯示B文檔", "ShowFile2View()", 0);
poCtrl1.addCustomToolButton("顯示比較結果", "ShowCompareView()", 0);
poCtrl1.setSaveFilePage("/SaveFile");
poCtrl1.wordCompare("doc/A.doc", "doc/B.doc", OpenModeType.docAdmin, "用戶名");//關鍵代碼,同時打開兩個word文檔來對比

 

  Html頁面js:

  <script language="javascript" type="text/javascript">
        function SaveDocument() {
            document.getElementById("PageOfficeCtrl1").WebSave();
        }
        function ShowFile1View() {
            document.getElementById("PageOfficeCtrl1").Document.ActiveWindow.View.ShowRevisionsAndComments = false;
            document.getElementById("PageOfficeCtrl1").Document.ActiveWindow.View.RevisionsView = 1;
        }
        function ShowFile2View() {
            document.getElementById("PageOfficeCtrl1").Document.ActiveWindow.View.ShowRevisionsAndComments = false;
            document.getElementById("PageOfficeCtrl1").Document.ActiveWindow.View.RevisionsView = 0;
        }
        function ShowCompareView() {
            document.getElementById("PageOfficeCtrl1").Document.ActiveWindow.View.ShowRevisionsAndComments = true;
            document.getElementById("PageOfficeCtrl1").Document.ActiveWindow.View.RevisionsView = 0;
        }
        function SetFullScreen() {
            document.getElementById("PageOfficeCtrl1").FullScreen = !document.getElementById("PageOfficeCtrl1").FullScreen;
        }
    </script>

  Html代碼中顯示PageOffice的代碼:

<div style="width:1000px; height:800px;">
    <%=poCtrl1.getHtmlCode("PageOfficeCtrl1")%>
</div>

  文件對比效果:顯示A文檔內容

  

  文件對比效果:顯示B文檔內容

  

  文件對比效果:顯示對比結果

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM