Convert java to open word document online

1. Material preparation

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

  

2. Implementation steps:

  1. Open the "integrated file" 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

<!-- PageOffice Begin -->
    <servlet>
        <servlet-name>poserver</servlet-name>
        <servlet-class>com.zhuozhengsoft.pageoffice.poserver.Server</servlet-class>
    </servlet>
    <servlet -mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/poserver.zz</url-pattern>
    </servlet-mapping>
    <
        <servlet-name>poserver</servlet-name>
        <url-pattern>/sealsetup.exe</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/posetup.exe</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/pageoffice.js</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/jquery.min.js</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/pobstyle.css</url-pattern>
    </servlet-mapping>
    <!-- PageOffice End-->
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 ;');">Open Word online</a>
  4. Add the import package on the page that calls PageOffice products (for example: word.jsp): com.zhuozhengsoft.pageoffice.*

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

    PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
    poCtrl1.setServerPage("poserver.zz"); //此行必须
    poCtrl1.setSaveFilePage("savefile.jsp");//To save the file, this line must
    // open the file
    poCtrl1.webOpen("D:\\1.doc", OpenModeType.docNormalEdit, "username");
  6 .In the body of the html code, insert the following code at the position where the office interface needs to appear:

<%=poCtrl1.getHtmlCode("PageOfficeCtrl1")%>
  7. In the action method or RequestMapping method or jsp page that handles file saving (for example: savefile.jsp), add the code for processing 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. Reference materials and examples 

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

Guess you like

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