Advertisement

java 集成pageoffice_Java集成PageOffice在线打开编辑word文件 - Spring Boot

阅读量:

开发环境: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方法:
69c5a8ac3fa60e0848d784a6dd461da6.png@RequestMapping(value="/word", method=RequestMethod.GET)public ModelAndView showWord(HttpServletRequest request, Map map){

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

}

@RequestMapping(value="/index", method=RequestMethod.GET)public ModelAndView showIndex(){

ModelAndView mv = new ModelAndView("Index"); return mv;

}
69c5a8ac3fa60e0848d784a6dd461da6.png

5. 新建Thymeleaf模板页:Word.html、Index.html;

6. 运行demo项目,并成功访问:http://localhost:8080/index

二、 集成PageOffice

1. 在pom.xml中添加PageOffice的依赖:
69c5a8ac3fa60e0848d784a6dd461da6.png

org.xerial

sqlite-jdbc

3.7.2

com.zhuozhengsoft

pageoffice

4.3.0.2
69c5a8ac3fa60e0848d784a6dd461da6.png

2. 在application.properties文件中添加两个自定义参数配置,posyspath:指定一个磁盘目录用来存放PageOffice注册成功之后生成的license.lic文件;popassword:设置PageOffice自带印章管理程序的登录密码;以备给PageOffice的服务器端Servlet程序使用:
69c5a8ac3fa60e0848d784a6dd461da6.png########################################################

###PageOffice

########################################################

posyspath=d:/lic/

popassword=111111
69c5a8ac3fa60e0848d784a6dd461da6.png

3. 在DemoController中添加代码获取上一步在application.properties中定义的两个参数:
69c5a8ac3fa60e0848d784a6dd461da6.png@Value("${posyspath}")

private String poSysPath;

@Value("${popassword}")

private String poPassWord;
69c5a8ac3fa60e0848d784a6dd461da6.png

4. 在DemoController中添加PageOffice的Servlet的注册代码:
69c5a8ac3fa60e0848d784a6dd461da6.png= = "/poserver.zz""/posetup.exe""/pageoffice.js""/jquery.min.js""/pobstyle.css""/sealsetup.exe"
69c5a8ac3fa60e0848d784a6dd461da6.png

5. 在DemoController的showWord方法中添加创建PageOfficeCtrl对象的代码,其中WebOpen方法的第一个参数是office文件在服务器端的磁盘路径,在此demo中暂时使用常量:d:\ test.doc
69c5a8ac3fa60e0848d784a6dd461da6.png@RequestMapping(value="/word", method=RequestMethod.GET) public ModelAndView showWord(HttpServletRequest request, Map 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;

}
69c5a8ac3fa60e0848d784a6dd461da6.png

6. 在Word.html中添加PageOffice客户端控件所在的div和js代码:
69c5a8ac3fa60e0848d784a6dd461da6.png
69c5a8ac3fa60e0848d784a6dd461da6.png

7. 在Word.html中添加pageoffice.js和jquery.min.js的引用,并添打开文件的超链接:

打开文件

8. 在DemoController添加saveFile方法,用来接收PageOffice客户端上传的文件流并保存到服务器指定磁盘目录,在此demo中暂时使用常量:d:\
69c5a8ac3fa60e0848d784a6dd461da6.png@RequestMapping("/save") public void saveFile(HttpServletRequest request, HttpServletResponse response){

FileSaver fs = new FileSaver(request, response);

fs.saveToFile("d:\ " + fs.getFileName());

fs.close();

}
69c5a8ac3fa60e0848d784a6dd461da6.png

9. 在d盘根目录下准备一个test.doc文件(不要用0字节的文件)以备测试;

10. 运行demo项目,访问:http://localhost:8080/index点击“打开文件”的超链接即可在线打开、编辑和保存文件。

三、×××

下载地址:http://www.zhuozhengsoft.com/download/PageOffice4.3.0.2ForSpringBoot.zip

全部评论 (0)

还没有任何评论哟~