• PageOffice 页面中打开office编辑文档


     

    ---pom.xml

    <!-- PageOffice插件 -->
    <dependency>
    <groupId>com.zhuozhengsoft</groupId>
    <artifactId>pageoffice</artifactId>
    <version>4.5.0.6</version>

    --------------web.xml

    <!-- PageOffice Begin -->
    <servlet>
    <servlet-name>poserver</servlet-name>
    <servlet-class>com.zhuozhengsoft.pageoffice.poserver.Server</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>poserver</servlet-name>
    <url-pattern>/poserver.zz</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>poserver</servlet-name>
    <url-pattern>/sealsetup.exe</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>poserver</servlet-name>
    <url-pattern>/posetup.exe</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>poserver</servlet-name>
    <url-pattern>/pageoffice.js</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>poserver</servlet-name>
    <url-pattern>/jquery.min.js</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>poserver</servlet-name>
    <url-pattern>/pobstyle.css</url-pattern>
    </servlet-mapping>
    <servlet>
    <servlet-name>adminseal</servlet-name>
    <servlet-class>com.zhuozhengsoft.pageoffice.poserver.AdminSeal</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>adminseal</servlet-name>
    <url-pattern>/adminseal.zz</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>adminseal</servlet-name>
    <url-pattern>/loginseal.zz</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>adminseal</servlet-name>
    <url-pattern>/sealimage.zz</url-pattern>
    </servlet-mapping>
    <mime-mapping>
    <extension>mht</extension>
    <mime-type>message/rfc822</mime-type>
    </mime-mapping>
    <context-param>
    <param-name>adminseal-password</param-name>
    <param-value>111111</param-value>
    </context-param>
    <!-- PageOffice End -->

    ---------service方法

    /**
    * 读写服务器文档资源
    */
    @Override
    public void readAndWirte(HttpServletRequest request,String fileSavePath) {
    //前台传来的文件路径
    String filePath = request.getParameter("filePath");
    filePath=filePath.replace("/", "\");
    String fileName = filePath.substring(filePath.lastIndexOf("\")+1);
    // 设置PageOffice服务器组件
    PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
    poCtrl1.setServerPage(request.getContextPath() + "/poserver.zz"); // 此行必须
    poCtrl1.setTitlebar(false); // 隐藏标题栏(pageoffice的标题)
    poCtrl1.setFileTitle(fileName);
    poCtrl1.setMenubar(true); // 隐藏菜单栏(文件一个设置)
    poCtrl1.setOfficeToolbars(true);// 隐藏Office工具条(word 的编辑按钮)
    poCtrl1.setCustomToolbar(true);// 隐藏自定义工具栏(保存 关闭 全屏)
    poCtrl1.addCustomToolButton("保存并关闭", "Save", 1);
    poCtrl1.addCustomToolButton("打印", "ShowPrintDlg()", 6);
    poCtrl1.addCustomToolButton("全屏切换", "SwitchFullScreen()", 4);
    // 设置保存路径
    poCtrl1.setSaveFilePage(request.getSession().getServletContext()
    .getContextPath()
    + fileSavePath+"?fileId="+request.getParameter("fileId"));
    //根据文件类型判断
    String wordType=filePath.substring(filePath.lastIndexOf(".")+1);
    //打开的文档类型
    if("doc".equals(wordType)||"docx".equals(wordType)){
    // word
    poCtrl1.webOpen(filePath, OpenModeType.docNormalEdit, "Word.Document");
    }else if("ppt".equals(wordType)||"pptx".equals(wordType)){
    // ppt
    poCtrl1.webOpen(filePath, OpenModeType.pptNormalEdit, "Word.Document");
    }else if("xls".equals(wordType)||"xlsx".equals(wordType)){
    // excel
    poCtrl1.webOpen(filePath, OpenModeType.xlsNormalEdit, "Word.Document");
    }
    // 文件打开形式 office/wps
    poCtrl1.setOfficeVendor(OfficeVendorType.MSOffice);
    // 页面展示的控件ID
    poCtrl1.setTagId("PageOfficeCtrl1");
    request.setAttribute("poCtrl1", poCtrl1);
    request.setAttribute("filePath", filePath);
    }

    /**
    * 只读服务器文档资源
    */
    @Override
    public void readOnly(HttpServletRequest request) {
    // //前台传来的文件路径
    String filePath = request.getParameter("filePath");
    filePath=filePath.replace("/", "\");
    String fileName = filePath.substring(filePath.lastIndexOf("\")+1);
    // 设置PageOffice服务器组件
    // 设置PageOffice服务器组件
    PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
    poCtrl1.setServerPage(request.getContextPath() + "/poserver.zz"); // 此行必须
    poCtrl1.setTitlebar(false); // 隐藏标题栏(pageoffice的标题)
    poCtrl1.setMenubar(true); // 隐藏菜单栏(文件一个设置)
    poCtrl1.setOfficeToolbars(false);// 隐藏Office工具条(word 的编辑按钮)
    poCtrl1.setCustomToolbar(true);// 隐藏自定义工具栏(保存 关闭 全屏)
    poCtrl1.addCustomToolButton("关闭", "CloseWindow()", 1);
    poCtrl1.addCustomToolButton("打印", "ShowPrintDlg()", 6);
    poCtrl1.addCustomToolButton("全屏切换", "SwitchFullScreen()", 4);
    try {
    request.setCharacterEncoding("utf-8");
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    }
    //根据文件类型判断
    String wordType=fileName.substring(fileName.lastIndexOf(".")+1);
    //打开的文档类型
    if("doc".equals(wordType)||"docx".equals(wordType)){
    // word
    poCtrl1.webOpen(filePath, OpenModeType.docNormalEdit, "Word.Document");
    }else if("ppt".equals(wordType)||"pptx".equals(wordType)){
    // ppt
    poCtrl1.webOpen(filePath, OpenModeType.pptNormalEdit, "Word.Document");
    }else if("xls".equals(wordType)||"xlsx".equals(wordType)){
    // excel
    poCtrl1.webOpen(filePath, OpenModeType.xlsNormalEdit, "Word.Document");
    }
    // 文件打开形式 office/wps
    poCtrl1.setOfficeVendor(OfficeVendorType.MSOffice);
    // 页面展示的控件ID
    poCtrl1.setTagId("PageOfficeCtrl1");
    request.setAttribute("poCtrl1", poCtrl1);
    request.setAttribute("pageTitle", fileName);
    }

    /**
    * PageOffice服务器文档资源保存
    */
    @Override
    public void fileSave(HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    request.setCharacterEncoding("utf-8");
    FileSaver fs = new FileSaver(request, response);
    // 文件路径
    String filePath = attachmentService.findOne(request.getParameter("fileId")).getUrl();
    filePath=filePath.replace("/", "\");
    fs.saveToFile(filePath);
    fs.close();
    }

    --------页面走后台跳转,需要用pobrowser 防止浏览器不支持

    <a id="wenjian" hidden="hidden" href="javascript:POBrowser.openWindowModeless('readOnly?filePath=D:/UploadFile/jxbgwh/111.doc','width=800px;height=700px;')"></a>

    ---------------------打开的页面设置

    <%@ page contentType="text/html;charset=UTF-8"%>
    <%@ page import="com.zhuozhengsoft.pageoffice.*,java.awt.*"%>
    <%@ taglib uri="http://java.pageoffice.cn" prefix="po"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript" src="${request.getServletContext().getRealPath('/')}jquery.min.js"></script>
    <script type="text/javascript" src="${request.getServletContext().getRealPath('/')}pageoffice.js" id="po_js_main"></script>
    </head>
    <body>
    <po:PageOfficeCtrl id="PageOfficeCtrl1" />
    </body>
    <script type="text/javascript">
    function Save() {
    document.getElementById("PageOfficeCtrl1").WebSave();
    window.external.close();//关闭POBrowser窗口
    }
    function ShowPrintDlg() {
    document.getElementById("PageOfficeCtrl1").ShowDialog(4); //打印对话框
    }
    function SwitchFullScreen() {//全屏
    document.getElementById("PageOfficeCtrl1").FullScreen = !document
    .getElementById("PageOfficeCtrl1").FullScreen;
    }
    function CloseWindow(){
    document.getElementById("PageOfficeCtrl1").close();
    window.external.close();//关闭POBrowser窗口
    }
    </script>
    </html>

  • 相关阅读:
    51nod 1621 花钱买车牌 优先队列
    最大字段和 51nod 1049 水水水水水水水水水水水水
    大数相乘 51nod 1027 水题
    逆序数 51nod 1019 归并 分治
    最长公共子序列 LCS 递归 dp 51Nod 1006
    vc6 字体设置
    自行车维护大全(zz)
    DirectX 9.0 3D游戏开发编程基础 [书评](zz)
    二维线段树
    latex 引用文献 bib
  • 原文地址:https://www.cnblogs.com/liuys635/p/12692749.html
Copyright © 2020-2023  润新知