springboot整合pageoffice实现word在线编辑保存。(代码片段)

悲雨叹风 悲雨叹风     2022-12-20     610

关键词:

一、查看官网

http://www.zhuozhengsoft.com/

点击首页下载,进入页面:

最新得5.2,我们就下载5.2版本进行测试。

二、查看下载包

  1. Samples5 为示例文件。放入tomcat中得webapps可以直接访问。
    localhost:8080/Samples5/index.html
  2. 集成文件 里面有我们需要jar包

新建springboot项目以及简单测试这里就不多说了。

1、springboot 引入 pageoffice5.2.0.12.jar

2、springboot 引入thymleaf

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

3、编写配置文件


/**
 * PageOffice 配置类
 */
@Configuration
public class PageOfficeConfig 

    @Value("$file.save.path")
    String poSysPath;

    /**
     * 添加PageOffice的服务器端授权程序Servlet(必须)
     * @return
     */
    @Bean
    public ServletRegistrationBean servletRegistrationBean() 
        com.zhuozhengsoft.pageoffice.poserver.Server poserver = new com.zhuozhengsoft.pageoffice.poserver.Server();
        //设置PageOffice注册成功后,license.lic文件存放的目录
        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;
    



4、编写 index.html 和 word.html

4.1 index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- office插件js begin 必须引入-->
    <script type="text/javascript" src="/jquery.min.js"></script>
    <script type="text/javascript" src="/pageoffice.js" id="po_js_main"></script>
    <!-- end -->
</head>
<body>
<a href="javascript:POBrowser.openWindowModeless('word','width=1200px;height=800px;');">打开文件</a>
</body>
</html>

4.2 word.html

**<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<input id="Button1" type="button" value="隐藏/显示 标题栏"  onclick="return Button1_onclick()" />
<input id="Button2" type="button" value="隐藏/显示 菜单栏" onclick="return Button2_onclick()" />
<input id="Button3" type="button" value="隐藏/显示 自定义工具栏"  onclick="return Button3_onclick()" />
<input id="Button4" type="button" value="隐藏/显示 Office工具栏"  onclick="return Button4_onclick()" />

<div style="width:1000px;height:700px;" th:utext="$pageoffice"> </div>
<script type="text/javascript">

    function Save() 
        document.getElementById("PageOfficeCtrl1").WebSave();
    
    function PrintFile()
        document.getElementById("PageOfficeCtrl1").ShowDialog(4);

    
    function IsFullScreen()
        document.getElementById("PageOfficeCtrl1").FullScreen = !document.getElementById("PageOfficeCtrl1").FullScreen;

    
    function CloseFile()
        window.external.close();
    

    function BeforeBrowserClosed()
        if (document.getElementById("PageOfficeCtrl1").IsDirty)
            if(confirm("提示:文档已被修改,是否继续关闭放弃保存 ?"))
            
                return  true;

            else

                return  false;
            

        
    

    // 隐藏/显示 标题栏
    function Button1_onclick() 
        var bVisible = document.getElementById("PageOfficeCtrl1").Titlebar;
        document.getElementById("PageOfficeCtrl1").Titlebar = !bVisible;
    

    // 隐藏/显示 菜单栏
    function Button2_onclick() 
        var bVisible = document.getElementById("PageOfficeCtrl1").Menubar;
        document.getElementById("PageOfficeCtrl1").Menubar = !bVisible;
    


    // 隐藏/显示 自定义工具栏
    function Button3_onclick() 
        var bVisible = document.getElementById("PageOfficeCtrl1").CustomToolbar;
        document.getElementById("PageOfficeCtrl1").CustomToolbar = !bVisible;
    
    // 隐藏/显示 Office工具栏
    function Button4_onclick() 
        var bVisible = document.getElementById("PageOfficeCtrl1").OfficeToolbars;
        document.getElementById("PageOfficeCtrl1").OfficeToolbars = !bVisible;
    
</script>
</body>
</html>**

5、编写PageOfficeController


/**
 * PageOffice Demo
 */
@Controller
@RequestMapping("/page")
public class PageOfficeController 

    /**
     * 进入测试
     * @return
     */
    @RequestMapping(value="/index", method=RequestMethod.GET)
    public ModelAndView showIndex()
        ModelAndView mv = new ModelAndView("index");
        return mv;
    

    /**
     * office online打开
     * @param request
     * @param map
     * @return
     */
    @RequestMapping(value="/word", method=RequestMethod.GET)
    public ModelAndView showWord(HttpServletRequest request, Map<String,Object> map)

        //--- PageOffice的调用代码 开始 -----
        PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
        poCtrl.setServerPage("/poserver.zz");//设置授权程序servlet
        poCtrl.addCustomToolButton("保存","Save()",1); //添加自定义按钮
        poCtrl.addCustomToolButton("打印", "PrintFile()", 6);
        poCtrl.addCustomToolButton("全屏/还原", "IsFullScreen()", 4);
        poCtrl.addCustomToolButton("关闭", "CloseFile()", 21);
        poCtrl.setSaveFilePage("/page/save");//设置保存的action
        poCtrl.webOpen("D:\\\\page\\\\test.docx", OpenModeType.docAdmin,"张三");
        poCtrl.setCaption("信息平台");
        map.put("pageoffice",poCtrl.getHtmlCode("PageOfficeCtrl1"));
        //--- PageOffice的调用代码 结束 -----
        ModelAndView mv = new ModelAndView("word");
        return mv;
    

    /**
     * 保存
     * @param request
     * @param response
     */
    @RequestMapping("/save")
    public void saveFile(HttpServletRequest request, HttpServletResponse response)
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile("d:\\\\page\\\\" + fs.getFileName());
        fs.close();
    



6.application.yml 配置

server:
  port: 8080
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC
    username: root
    password: finn123

  # thymeleaf页面模板配置
  thymeleaf:
    prefix: classpath:/templates/
    suffix: .html
  mvc:
    view:
      prefix: classpath:/templates/
      suffix: .html
  resources:
    static-locations: classpath:/templates/,classpath:/static/
file:
  save:
    path: d:/page/

7.注意

项目结构

注意jquery.min.js 和 pageoffice.js文件地址

三、测试

输入网址

http://localhost:8080/page/index

打开文件,或让你先进行下载pageoffice。

注意事项

  1. 关闭浏览器进行安装
  2. 二要进行企业注册,随便填填
  3. test.docx得文件需要填写些数据。空文档打不开!

四、gitee地址

https://gitee.com/finn_feng/finnPageOffice.git

参考:
找不到了…

springboot整合springsecurity实现权限控制:菜单管理(代码片段)

系列文章目录《SpringBoot整合SpringSecurity实现权限控制(一):实现原理》《SpringBoot整合SpringSecurity实现权限控制(二):权限数据基本模型设计》《SpringBoot整合SpringSecurity实现权限控制(三):... 查看详情

springboot整合vue实现上传下载文件(代码片段)

springboot整合vue实现上传下载文件文章目录springboot整合vue实现上传下载文件1上传下载文件api文件2.上传大文件配置3.vue前端主要部分环境springboot1.5.x完整代码下载:springboot整合vue实现上传下1上传下载文件api文件设置上传路径&... 查看详情

[springboot系列]springboot如何整合ssmp

文章目录基于SpringBoot实现SSMP整合基于SpringBoot实现SSMP整合SpringBoot之所以好用,就是它能方便快捷的整合其他技术,这里我们先介绍四种技术的整合:整合JUnit整合MyBatis整合MyBatis-Plus整合Druid整合JUnitSpringBoot技术的定位用于简化... 查看详情

springboot+mybatis整合

  LZ今天自己搭建了下Springboot+Mybatis,比原来的Spring+SpringMVC+Mybatis简单好多。其实只用Springboot也可以开发,但是对于多表多条件分页查询,Springboot就有点力不从心了,所以LZ把Mybatis整合进去,不得不说,现在的框架搭建真的... 查看详情

springboot4.springboot整合devtools实现热部署

一、添加devtools依赖<!--Springboot热部署:此热部署会遇到java.lang.ClassCastException异常--><!--optional=true,依赖不会传递,该项目依赖devtools;之后依赖myboot项目的项目如果想要使用devtools,需要重新引入--><dependency><groupId>... 查看详情

精通springboot--整合redis实现缓存

今天我们来讲讲怎么在springboot中整合redis实现对数据库查询结果的缓存。首先第一步要做的就是在pom.xml文件添加spring-boot-starter-data-redis。要整合缓存,必不可少的就是我们要继承一个父类CachingConfigurerSupport。我们先看看这个类... 查看详情

springboot整合shiro实现权限控制(代码片段)

文章目录1、SpringBoot整合Shiro1.1、shiro简介1.2、代码的具体实现1.2.1、Maven的配置1.2.2、整合需要实现的类1.2.3、项目结构1.2.4、ShiroConfig的实现1.2.5、CustomerRealm的实现1.2.6、shiro缓存配置1.2.7、主页index.html的设置1.3、简单测试1.3.1、adm... 查看详情

springboot整合shiro实现权限控制(代码片段)

文章目录1、SpringBoot整合Shiro1.1、shiro简介1.2、代码的具体实现1.2.1、Maven的配置1.2.2、整合需要实现的类1.2.3、项目结构1.2.4、ShiroConfig的实现1.2.5、CustomerRealm的实现1.2.6、shiro缓存配置1.2.7、主页index.html的设置1.3、简单测试1.3.1、adm... 查看详情

shiro整合springboot缓存之redis实现(代码片段)

Shiro整合Springboot缓存之Redis实现Redis下载安装引入redis依赖配置redis连接启动redis服务自定义redis缓存的实现自定义shiro缓存管理器自定义salt实现实现序列化接口自定义Realm改造开启redis缓存Redis下载安装Windows系统中Redis下载安装其它... 查看详情

springboot2基于springboot实现ssmp整合(代码片段)

前言​    重头戏来了,SpringBoot之所以好用,就是它能方便快捷的整合其他技术,本文讲解一些技术的整合方式,通过这本文的学习,感受SpringBoot到底有多酷炫。本文学习如下技术的整合方式整合JUnit整... 查看详情

springboot整合redis实现缓存

...纲一、缓存的应用场景二、更新缓存的策略三、运行 springboot-mybatis-redis 工程案例四、springboot-mybatis-redis 工程代码配置详解 运行环境:MacOS10.12.xJDK8+Redis3.2.8SpringBoot1.5.1.RELEASE 一、缓存的应用场景什么是缓存?... 查看详情

springboot整合elasticsearch实现多版本的兼容

前言在上一篇学习SpringBoot中,整合了Mybatis、Druid和PageHelper并实现了多数据源的操作。本篇主要是介绍和使用目前最火的搜索引擎ElastiSearch,并和SpringBoot进行结合使用。ElasticSearch介绍ElasticSearch是一个基于Lucene的搜索服务器,其... 查看详情

springboot整合rocketmq实现入门案例

...习了Spring整合RocketMQ的第一个案例!现在我们来学习SpringBoot如何整合RocketMQ实现更加简单的使用!文章目录1创建maven项目2配置文件3生产者4消费者5测试1创建maven项目创建一个maven项目。引入sp 查看详情

springboot整合websocket

...t:在浏览器和服务器之间建立tcp连接,实现全双工通信??springboot使用websocket有两种方式,一种是实现简单的websocket,另外一种是实现STOMP协议。这一篇实现简单的webso 查看详情

springboot整合mybatis实现逆向工程

springboot整合mybatis创建逆向工程,快速的创建pojo实体,dao接口,mapperxml文件第一步添加依赖<projectxmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mave 查看详情

shiro整合springboot之图片验证码实现(代码片段)

Shiro整合Springboot之图片验证码实现开发控制器放行验证码新增验证码工具类开发页面修改认证流程开发控制器/***验证码方法*/@RequestMapping("getImage")publicvoidgetImage(HttpSessionsession,HttpServletResponseresponse)throwsIOException//生成验... 查看详情

springboot整合rabbitmq实现死信队列(代码片段)

...bitMQ实现生产消费(7种通讯方式),本文基于SpringBoot实现RabbitMQ中的死信队列和延迟队列。概 查看详情

springboot整合thumbnailator实现图片压缩

springboot整合thumbnailator实现图片压缩前言最近由于首页产品列表图片显示太慢,经过研究发现是用户上传的图片太大。针对这个问题,想到的解决方案是:1、产品上传时,限定图片上传大小不超过2m2、上传成功后将产品图片进行... 查看详情