2023年11月28日发(作者:)

(转)使⽤PageOffice实现⽂档(word,excel,pdf)在线预览

编辑

1、安装完后需要给⾃⼰的项⽬添加pageoffice4. 和java 添加jar包没有区别。

2、启动的时候第⼀次使⽤试⽤版会弹出⼀个框,需要添加⼀些信息,有⼀个序列号在最后我写了。剩下 那个就是随便填写就可以。同时他

会⽣成⼀个⽂件就是。他会在tomcat 项⽬部署的lib下。假如每次启动都需要添加的话。你就需要把tomcat 部署项⽬lib ⾥的

复制到你的本地项⽬中。

3、预览后台代码:

1. public String openbar(HttpServletRequest request, HttpServletResponse response, @PathVariable int id,

2. @PathVariable int flag) {

3. // 设置PageOffice服务器组件

4. PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);

5. ribute("poCtrl1", poCtrl1);

6. verPage(textPath() + "/"); // 此⾏必须

7. lebar(false); // 隐藏标题栏(pageoffice的标题)

8. ubar(false); // 隐藏菜单栏(⽂件⼀个设置)

9. iceToolbars(false);// 隐藏Office⼯具条(word 的编辑按钮)

0. // tomToolbar(false);// 隐藏⾃定义⼯具栏(保存 关闭 全屏)

1. tomToolButton("打印", "ShowPrintDlg()", 6);

2. tomToolButton("全屏切换", "SwitchFullScreen()", 4);

3. tomToolButton("关闭", "close", 21);

4. List entity = t(getEntity(flag, id));

5. String path = h((0));

6. String realpath = e("/", "");

7. String suffix = ing(dexOf(".") + 1);

8. if ("doc".equals(suffix) || "docx".equals(suffix)) {

9. n(realpath, dOnly, "张三");

0. } else if ("xls".equals(suffix) || "xlsx".equals(suffix)) {

1. n(realpath, dOnly, "张三");

2. }

3. // 打开⽂件

4. return "OpenWord";

5. }

4'、在线编辑:

1. /**

2. * 在线编辑

3. *

4. * @param request

5. * @param response

6. * @param id

7. * @param flag

8. * @return

9. */

0. n(realpath, malEdit, "张三");

1. } else if ("xls".equals(suffix) || "xlsx".equals(suffix)) {

2. n(realpath, malEdit, "张三");

3. }

4. return "Word";

5. }

5、在线编辑需要保存,所以有在线保存:

1. /**

4. ();

5. }

6、web-xml配置

9.

0.

1. adminseal

2. eal

4. <%

5. PageOfficeCtrl poCtrl = (PageOfficeCtrl) ribute("poCtrl");

6. %>

7.

8.

9.

0.

1. </span><span style='font-size:13.169px;color:#4c4c4c;letter-spacing:0.013px;font-family:HiraginoSansGB-W3;'>最简单的打开保存</span><span style='font-size:13.169px;color:#4c4c4c;letter-spacing:-0.024px;font-family:NimbusSanL-Regu;'>Word</span><span style='font-size:13.169px;color:#4c4c4c;letter-spacing:0.013px;font-family:HiraginoSansGB-W3;'>⽂件</span><span style='font-size:13.169px;color:#4c4c4c;letter-spacing:-0.045px;font-family:NimbusSanL-Regu;'>

2.