Java在线生成word excel 文档 -----Springmvc_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Java在线生成word excel 文档 -----Springmvc

Java在线生成word excel 文档 -----Springmvc

 2018/10/9 15:24:36  妮子321  程序员俱乐部  我要评论(0)
  • 摘要:此示例演示用pageoffice在线打开编辑保存office办公文档需要用到的jar包(http://www.zhuozhengsoft.com/dowm/?v=4)下载试用程序包pageoffice4.5.0.4.jar1.WEB.XML<!--PageOfficeBegin--><servlet><servlet-name>poserver</servlet-name><servlet-class>com
  • 标签:MVC 生成WORD excel 文档 Java Spring 在线

此示例演示用 pageoffice 在线打开编辑保存office 办公文档

需要用到的jar包(http://www.zhuozhengsoft.com/dowm/?v=4)下载试用程序包

pageoffice4.5.0.4.jar

1.WEB.XML

monospace; font-size: 13px; display: block; overflow: auto; padding: 10px; border-radius: 3px; line-height: 1.4;" class="hljs 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 -->

	<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.xml

<!-- 开始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页面

(1):index.jsp

javascript"><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.jsp

		<script type="text/javascript">
	function">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:后台代码

打开文档代码

@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

发表评论
用户名: 匿名