Vue3.x+springboot集成pageoffice

说明:由于pageoffice浏览器是ie内核,vue3不兼容ie。所以需要把页面放在后端

一,前端项目:

1、index.html页面引用pageoffice.js

 <script type="text/javascript" src="http://localhost:8081/springboot-pageoffice-demo/pageoffice.js"></script>

2、在index.vue页面添加一个按钮,调用POBrowser.openWindowModeless请求后端。http://localhost:8081/springboot-pageoffice-demo/SimpleWord/Word2 是后端打开文件的controller

POBrowser.openWindowModeless('http://localhost:8081/springboot-pageoffice-demo/SimpleWord/Word2', 'width=1150px;height=900px;');

二、后端项目

1、打开文件的controller,返回ModeAndView,后端html模板一般用thymeleaf或者freemarker

@RequestMapping(value="SimpleWord/Word2")
	public ModelAndView showWord(HttpServletRequest request){

		PageOfficeCtrl poCtrl=new PageOfficeCtrl(request);
		poCtrl.setServerPage(request.getContextPath()+"/poserver.zz");//设置服务页面
		poCtrl.addCustomToolButton("保存","Save",1);//添加自定义保存按钮
		poCtrl.setSaveFilePage("/saveFile");//设置处理文件保存的请求方法

		//打开word
		poCtrl.webOpen("D:\\doc\\template.doc",OpenModeType.docNormalEdit,"张三");

		request.setAttribute("pageoffice",poCtrl.getHtmlCode("PageOfficeCtrl1"));

		ModelAndView mv = new ModelAndView("Word");
		return mv;
	}

	

setServerPage中saveFile保存文件的方法

@RequestMapping(value="/saveFile")
	public void saveFile(HttpServletRequest request, HttpServletResponse response){

		FileSaver fs = new FileSaver(request, response);
		fs.saveToFile("D:\\doc\\"+ fs.getFileName());
		fs.close();
	}

2、Word.html页面,我用的thymeleaf

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <head>
        <title>打开Word文件</title>
    </head>
    <body style="overflow: hidden">
        <script type="text/javascript">
           //保存文件
          	function Save() {
                 document.getElementById("PageOfficeCtrl1").WebSave();
        	}
        	

        </script>
        <div style="width:auto;height:730px;" th:utext="${pageoffice}"></div>
    </body>
</html>

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值