开发环境:JDK1.8、Eclipse、Sping Boot + Thymeleaf框架。
一. 构建Sping Boot + Thymeleaf框架的项目(不再详述):
1. 新建一个maven project项目:demo。
2. 修改pom.xml配置,把项目配置为Spring Boot项目;
3. 配置Thymeleaf:添加Thymeleaf依赖,并在application.properties文件中添加Thymeleaf的配置;
4. 新建DemoController,添加showWord、showIndex方法:
@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. 新建Thymeleaf模板页:Word.html、Index.html;
6. 运行demo项目,并成功访问:http://localhost:8080/index
二、 集成PageOffice
1. 在pom.xml中添加PageOffice的依赖:
<!-- 添加Sqlite依赖(可选:如果不需要使用印章功能的话,不需要添加此依赖)--> <dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> <version>3.7.2</version> </dependency> <!-- 添加PageOffice依赖(必须) --> <dependency> <groupId>com.zhuozhengsoft</groupId> <artifactId>pageoffice</artifactId> <version>4.3.0.2</version> </dependency>
2. 在application.properties文件中添加两个自定义参数配置,posyspath:指定一个磁盘目录用来存放PageOffice注册成功之后生成的license.lic文件;popassword:设置PageOffice自带印章管理程序的登录密码;以备给PageOffice的服务器端Servlet程序使用:
######################################################## ###PageOffice ######################################################## posyspath=d:/lic/ popassword=111111
3. 在DemoController中添加代码获取上一步在application.properties中定义的两个参数:
@Value("${posyspath}") private String poSysPath; @Value("${popassword}") private String poPassWord;
4. 在DemoController中添加PageOffice的Servlet的注册代码:
/** * 添加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; // }
5. 在DemoController的showWord方法中添加创建PageOfficeCtrl对象的代码,其中WebOpen方法的第一个参数是office文件在服务器端的磁盘路径,在此demo中暂时使用常量:d:\\test.doc
@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.setSaveFilePage("/save");//设置保存的action poCtrl.webOpen("d:\\test.doc",OpenModeType.docAdmin,"张三"); map.put("pageoffice",poCtrl.getHtmlCode("PageOfficeCtrl1")); //--- PageOffice的调用代码 结束 ----- ModelAndView mv = new ModelAndView("Word"); return mv; }
6. 在Word.html中添加PageOffice客户端控件所在的div和js代码:
<div style="width:1000px;height:700px;" th:utext="${pageoffice}"> </div> <script type="text/javascript"> function Save() { document.getElementById("PageOfficeCtrl1").WebSave(); } </script>
7. 在Word.html中添加pageoffice.js和jquery.min.js的引用,并添打开文件的超链接:
<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;');">打开文件</a>
8. 在DemoController添加saveFile方法,用来接收PageOffice客户端上传的文件流并保存到服务器指定磁盘目录,在此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. 在d盘根目录下准备一个test.doc文件(不要用0字节的文件)以备测试;
10. 运行demo项目,访问:http://localhost:8080/index点击“打开文件”的超链接即可在线打开、编辑和保存文件。
三、源码下载
下载地址:http://www.zhuozhengsoft.com/download/PageOffice4.3.0.2ForSpringBoot.zip
相关推荐
在本项目中,我们将探讨如何使用SpringBoot框架与PageOffice集成,实现在线实时编辑Word和Excel的功能。SpringBoot以其简洁的配置和快速的开发能力,成为Java领域中备受青睐的微服务框架。而PageOffice则是一款强大...
SpringBoot(30) 整合PageOffice实现在线编辑Word和Excel
**SpringBoot集成Page...通过以上步骤,你可以在SpringBoot项目中成功集成PageOffice,实现Web应用的在线Office文档处理功能。但要注意,实际应用中可能还需要根据业务需求进行定制和优化,确保用户体验和系统稳定性。
5. **集成Web应用**:PageOffice可以无缝集成到Java Web应用中,如Spring Boot、Struts、JSF等框架,实现Web应用中的Word文档生成和下载功能。 6. **安全机制**:PageOffice提供了一些安全机制,如防止内存泄漏、...
在IT行业中,集成OpenOffice与SpringBoot框架来实现在线预览PPT、Word和Excel是一项常见的需求,尤其在开发Web应用时。OpenOffice是一个开源的办公软件套件,它提供了API,可以用来处理多种文档格式,包括ODF...
集成PageOffice至Spring Boot应用可以使应用程序具备处理Office文档的能力,提升用户体验。 首先,集成PageOffice的关键在于添加相应的依赖。在项目pom.xml文件中,你需要引入PageOffice的Maven依赖: ```xml ...
PageOffice是一款专业的Java Web开发工具,它允许开发者在网页中实现对Office文档的在线编辑、预览和保存功能。此升级包"pageoffice4.5.0.3.jar"是针对先前版本的一个更新,旨在提升软件性能、修复已知问题以及增加...
本文将详细介绍如何使用Spring Boot集成PageOffice进行文档处理的开发过程。Spring Boot以其简洁、快速的特性在Java开发中广受欢迎,而PageOffice是一款强大的在线文档编辑控件,可以实现在Web环境下对各类办公文档...
SpringBoot默认集成了Spring Web模块,但为了实现报表功能,我们还需要添加如Apache POI(用于处理Microsoft Office格式)、iText(用于PDF处理)和JasperReports(用于报表设计)等库。在`pom.xml`文件中添加对应的...