Online opening of word documents in java

1. Material preparation

  Baidu: PageOffice, download PageOffice for Java from the official website. Compressed package file:

  

2. Implementation steps:

  1. Open the "Integration Files" directory, copy pageoffice4.4.0.2.jar in the "WEB-INF\lib" directory to the "WEB-INF\lib" directory of your own project

  2. Refer to the web.xml file in the "integration files" folder to configure the web.xml file in your web project, or you can directly add the following configuration to your web.xml;

Press Ctrl+C to copy the code

 

Press Ctrl+C to copy the code

  3. On the page that displays the file list (for example: doclist.jsp), add a reference to the pageoffice.js file and a hyperlink to open the file "Open Word Online":

<script type="text/javascript" src=" jquery.min.js"></script>
<script type="text/javascript" src=" pageoffice.js" id="po_js_main"></script>
......
<a href="javascript:POBrowser.openWindowModeless(/word.jsp','width=1200px;height=800px;');">在线打开Word</a>

  4. Add the import package on the page calling PageOffice products (for example: word.jsp): com.zhuozhengsoft.pageoffice.*

  5. Write the calling code of PageOffice and open the file online (for example: 1.doc in the root directory of the server D drive):

PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
    poCtrl1.setServerPage("poserver.zz"); //This line must
    poCtrl1.setSaveFilePage("savefile.jsp");//To save the file, this line must
    //open a file
    poCtrl1.webOpen("D:\\1.doc", OpenModeType.docNormalEdit, "Username");

  6. Insert the following code in the body of the html code where the office interface needs to appear:

<%=poCtrl1.getHtmlCode("PageOfficeCtrl1")%>

  7. Add the code for processing file saving in the action method or RequestMapping method or jsp page (for example: savefile.jsp) that handles file saving:

  FileSaver fs=new FileSaver(request,response);
  fs.saveToFile("d:\\1.doc");
  fs.close();

  8. Start the running project, visit the page of the file list (for example: doclist.jsp), and click the hyperlink of "Open Word Online" to view the effect of opening, editing, and saving word files online.

3. References and Examples 

  1. Deploy the PageOffice example: copy the Samples4 folder to the Webapps directory of Tomcat, visit: http://localhost:8080/Samples4/index.html
  2. Refer to the basic function example: 1. 2. Open the Office file by disk path (Take Word as an example)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325449191&siteId=291194637