Reproduced Java Integration Pageoffice Open edit Word file online-Spring Boot

Source: Internet
Author: User

Development environment: JDK1.8, Eclipse, sping Boot + thymeleaf framework.

A Project to build the sping Boot + thymeleaf Framework (no longer detailed):

1. Create a MAVEN Project project: Demo.

2. Modify the Pom.xml configuration to configure the project as the Spring Boot project;

3. Configure Thymeleaf: Add thymeleaf dependency and add thymeleaf configuration in application.properties file;

4. New Democontroller, add Showword, Showindex method:

@RequestMapping (value= "/word", method=requestmethod.get) public Modelandview Showword (HttpServletRequest request, Map<string,object> map) {    Modelandview mv = new Modelandview ("Word");    return MV;} @RequestMapping (value= "/index", method=requestmethod.get) public Modelandview Showindex () {    Modelandview mv = new Modelandview ("Index");    return MV;}

5. New Thymeleaf Template page: word.html, index.html;

6. Run the demo project and successfully visit: Http://localhost:8080/index

Second, integrated Pageoffice

  1. Add the Pageoffice dependency in Pom.xml:

<!--add SQLite dependency (optional: If you do not need to use the stamp function, you do not need to add this dependency)--><dependency>    <groupid>org.xerial</groupid >    <artifactId>sqlite-jdbc</artifactId>    <version>3.7.2</version></ dependency><!--Add Pageoffice dependency (required)--><dependency>    <groupid>com.zhuozhengsoft</ groupid>    <artifactId>pageoffice</artifactId>    <version>4.3.0.2</version>< /dependency>

2. Add two custom parameter configurations in the Application.properties file, Posyspath: Specify a disk directory to hold the License.lic file generated after the Pageoffice registration is successful; Popassword: Set Pageoffice self-contained seal tube The login password for the Pageoffice server-side servlet program to be used:

########################################################## #PageOffice ########################################## ############# #posyspath =d:/lic/popassword=111111

3. Add code in Democontroller get the two parameters defined in the previous step in application.properties:

@Value ("${posyspath}") private string Posyspath; @Value ("${popassword}") private string Popassword;

4. Add the registration code for the Pageoffice servlet in Democontroller:

     /**     * Add Pageoffice server-side Authorization program servlet (required)     * @return */    @Bean public    Servletregistrationbean Servletregistrationbean () {        Com.zhuozhengsoft.pageoffice.poserver.Server poserver = new Com.zhuozhengsoft.pageoffice.poserver.Server ();        Set Pageoffice Registration successful, license.lic file directory        poserver.setsyspath (posyspath);        Servletregistrationbean SRB = new Servletregistrationbean (poserver);        Srb.addurlmappings ("/poserver.zz");        Srb.addurlmappings ("/posetup.exe");        Srb.addurlmappings ("/pageoffice.js");        Srb.addurlmappings ("/jquery.min.js");        Srb.addurlmappings ("/pobstyle.css");        Srb.addurlmappings ("/sealsetup.exe");        return SRB;        //    }

5. Add the code that creates the Pageofficectrl object in the Showword method of Democontroller, where the first parameter of the Webopen method is the disk path on the server side of the Office file, and the constants are temporarily used in this demo: d:\\ Test.doc

  

    @RequestMapping (value= "/word", method=requestmethod.get) public    Modelandview Showword (httpservletrequest Request, map<string,object> Map) {        //---Pageoffice The calling code begins-----        Pageofficectrl poctrl=new Pageofficectrl (request);        Poctrl.setserverpage ("/poserver.zz");//Set the authorization program servlet        Poctrl.addcustomtoolbutton ("Save", "saved", 1);//Add Custom button        poctrl.setsavefilepage ("/save");//Set Save action        Poctrl.webopen ("D:\\test.doc", Openmodetype.docadmin, "Zhang San ");        Map.put ("Pageoffice", Poctrl.gethtmlcode ("PAGEOFFICECTRL1"));        ---pageoffice The call code ends-----        Modelandview mv = new Modelandview ("Word");        return MV;    }

6. Add the div and JS code for the Pageoffice client control in word.html:

<div style= "width:1000px;height:700px;" th:utext= "${pageoffice}" > </div><script type= "text/ JavaScript >    function Save () {        document.getElementById ("PageOfficeCtrl1"). WeBSave ();    } </script>

7. Add a reference to the Pageoffice.js and jquery.min.js in the word.html and a hyperlink to the Open file:

<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 ', ' width=1200px;height=800px; '); " > Open File </a>

8. Add the SaveFile method in Democontroller to receive the Pageoffice client uploaded file stream and save it to the server specified disk directory, and temporarily use the constant in this demo: d:\\

    @RequestMapping ("/save") public    void SaveFile (HttpServletRequest request, httpservletresponse response) {        Filesaver fs = new Filesaver (request, response);        Fs.savetofile ("d:\\" + fs.getfilename ());        Fs.close ();    }

9. Prepare a Test.doc file (do not use a 0-byte file) for testing in the D packing directory;

10. Run the demo project, Access: Http://localhost:8080/index Click on the "Open file" hyperlink to open, edit, and save the file online.

Third, the source code download

  : Http://www.zhuozhengsoft.com/download/PageOffice4.3.0.2ForSpringBoot.zip

Reproduced Java Integration Pageoffice Open edit Word file online-Spring Boot

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.