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文檔內容

  

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

  

發佈了33 篇原創文章 · 獲贊 18 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章