此示例演示用 pageoffice 在線打開編輯保存office 辦公文檔javascript
須要用到的jar包(http://www.zhuozhengsoft.com/dowm/?v=4)下載試用程序包css
pageoffice4.5.0.4.jarjava
1.WEB.XMLjquery
<!-- 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 --> <servlet> <servlet-name>chapter2</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>chapter2</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
2:spring-servlet.xmlweb
<!-- 開始spring mvc的註解 --> <mvc:annotation-driven/> <!-- 這樣根目錄下面的resource的文件(.css,.js等)就不會被spring的DispatchServlet進行過濾 --> <mvc:resources location="/resources/" mapping="/resources/**"/> <!-- 配置註解掃描的包路徑 --> <context:component-scan base-package="web"></context:component-scan> <!-- 配置action中返回的視圖配置 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"></property> <property name="suffix" value=".jsp"></property> </bean>
3:JSP頁面spring
(1):index.jsp服務器
<div style="text-align: center;"> <b>在線編輯保存Office文檔</b> <br> <a href="javascript:POBrowser.openWindowModeless('open.do?type=word' , 'width=1200px;height=800px;');">在線編輯保存Word文檔</a> <br> <a href="javascript:POBrowser.openWindowModeless('open.do?type=excel' , 'width=1200px;height=800px;');">在線編輯保存Word文檔</a> <br> </div>
(2)WordOrExcel.jspmvc
<script type="text/javascript"> function Save() { document.getElementById("PageOfficeCtrl1").WebSave(); window.external.close();//關閉POBrowser窗口 } </script> <div style="width: 100%; height: 100%;"> <% PageOfficeCtrl poCtrl = (PageOfficeCtrl) request .getAttribute("pageoffice"); %> <%=poCtrl.getHtmlCode("PageOfficeCtrl1")%> </div>
4:後臺代碼app
打開文檔代碼less
@RequestMapping("open") public String openword(HttpServletRequest request, HttpServletResponse response) { String type = request.getParameter("type"); PageOfficeCtrl poCtrl = new PageOfficeCtrl(request); // 設置服務器頁面 poCtrl.setServerPage(request.getContextPath() + "/poserver.zz"); // 設置保存的action poCtrl.setSaveFilePage("savefile.do"); // 設置打開的文檔 // 打開word if ("word".equals(type)) { poCtrl.webOpen("doc/test.doc", OpenModeType.docAdmin, "張三"); } if ("excel".equals(type)) { poCtrl.webOpen("doc/test.xls", OpenModeType.docAdmin, "張三"); } request.setAttribute("pageoffice", poCtrl); return "WordOrExcel"; }
保存代碼
@RequestMapping("savefile") public void savefile(HttpServletRequest request, HttpServletResponse response){ FileSaver fs = new FileSaver(request, response); fs.saveToFile(request.getSession().getServletContext().getRealPath("doc/") + "/" + fs.getFileName()); fs.close(); }
最後打開文檔的效果
打開文檔的時候須要註冊,這是一個試用的序列號
IMTG6-BSXJ-JGZ6-3BIWM