使⽤Springboot实现word在线编辑保存⽬录
⼀、查看官⽹
⼆、查看下载包
1、springboot 引⼊ pageoffice5.2.0.12.jar
2、springboot 引⼊thymleaf
3、编写配置⽂件
4、编写 index.html 和 word.html
4.1 index.html
4.2 word.html
5、编写PageOfficeController
l 配置
7.注意项⽬结构
三、测试
输⼊⽹址
注意事项
四、gitee地址
总结
⼀、查看官⽹
点击⾸页下载,进⼊页⾯:
最新得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("/");
srb.addUrlMappings("/");
srb.addUrlMappings("/pageoffice.js");
srb.addUrlMappings("/jquery.min.js");
srb.addUrlMappings("/pobstyle.css");
srb.addUrlMappings("/");
return srb;
}
}
4、编写 index.html 和 word.html
4.1 index.html
<!DOCTYPE html>
<html xmlns="/1999/xhtml" xmlns:th="">
<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="/1999/xhtml" xmlns:th="">
<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 th:utext="${pageoffice}"> </div>
<script type="text/javascript">
function Save() {
}
function PrintFile(){
}
function IsFullScreen(){
function CloseFile(){
}
function BeforeBrowserClosed(){
if (ElementById("PageOfficeCtrl1").IsDirty){
if(confirm("提⽰:⽂档已被修改,是否继续关闭放弃保存?"))
{
return true;
}else{
return false;
}
}
}
// 隐藏/显⽰标题栏
function Button1_onclick() {
var bVisible = ElementById("PageOfficeCtrl1").Titlebar;
}
// 隐藏/显⽰菜单栏
function Button2_onclick() {
var bVisible = ElementById("PageOfficeCtrl1").Menubar;
}
// 隐藏/显⽰⾃定义⼯具栏
function Button3_onclick() {
var bVisible = ElementById("PageOfficeCtrl1").CustomToolbar;
mysql的jar包下载ElementById("PageOfficeCtrl1").CustomToolbar = !bVisible;
}
/
/ 隐藏/显⽰ Office⼯具栏
function Button4_onclick() {
var bVisible = ElementById("PageOfficeCtrl1").OfficeToolbars;
}
</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("/");//设置授权程序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",HtmlCode("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();
}
}
l 配置
server:
port: 8080
spring:
datasource:
driver-class-name: sql.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⽂件地址
三、测试
输⼊⽹址
打开⽂件,或让你先进⾏下载pageoffice。
注意事项
1.关闭浏览器进⾏安装
2.⼆要进⾏企业注册,随便填填
四、gitee地址
总结
本篇⽂章就到这⾥了,希望能给你带来帮助,也希望您能够多多关注的更多内容!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论