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方法:

fz.gif

@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;

}

fz.gif

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

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

二、 集成PageOffice

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

fz.gif

org.xerial

sqlite-jdbc

3.7.2

com.zhuozhengsoft

pageoffice

4.3.0.2

fz.gif

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的注册代码:

fz.gif

/**

* 添加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;

//

}

fz.gif

5. 在DemoController的showWord方法中添加创建PageOfficeCtrl对象的代码,其中WebOpen方法的第一个参数是office文件在服务器端的磁盘路径,在此demo中暂时使用常量:d:\\test.doc

fz.gif

@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;

}

fz.gif

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

fz.gif

function Save() {

document.getElementById("PageOfficeCtrl1").WebSave();

}

fz.gif

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

打开文件

8. 在DemoController添加saveFile方法,用来接收PageOffice客户端上传的文件流并保存到服务器指定磁盘目录,在此demo中暂时使用常量:d:\\

fz.gif

@RequestMapping("/save")

public void saveFile(HttpServletRequest request, HttpServletResponse response){

FileSaver fs = new FileSaver(request, response);

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

fs.close();

}

fz.gif

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

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

三、源码下载

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值