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

原文链接: https://my.oschina.net/u/3507515/blog/2218592

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

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

pageoffice4.5.0.4.jar

1.WEB.XML


	
		poserver
		com.zhuozhengsoft.pageoffice.poserver.Server
	
	
		poserver
		/poserver.zz
	
	
		poserver
		/sealsetup.exe
	
	
		poserver
		/posetup.exe
	
	
		poserver
		/pageoffice.js
	
	
		poserver
		/jquery.min.js
	
	
		poserver
		/pobstyle.css
	
	
		adminseal
		com.zhuozhengsoft.pageoffice.poserver.AdminSeal
	
	
		adminseal
		/adminseal.zz
	
	
		adminseal
		/loginseal.zz
	
	
		adminseal
		/sealimage.zz
	
	
		mht
		message/rfc822
	
	
		adminseal-password
		111111
	
	

	
		chapter2
		org.springframework.web.servlet.DispatcherServlet
		
			contextConfigLocation
			/WEB-INF/spring-servlet.xml
		
		1
	

	
		chapter2
		*.do
	

2:spring-servlet.xml


	
	
	
	
	
	
	
	
	
	
		
		
	

3:JSP页面

(1):index.jsp

(2)WordOrExcel.jsp

		
		
<% PageOfficeCtrl poCtrl = (PageOfficeCtrl) request .getAttribute("pageoffice"); %> <%=poCtrl.getHtmlCode("PageOfficeCtrl1")%>

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();
	}

 

 

最后打开文档的效果

Java在线生成word excel 文档 -----Springmvc_第1张图片

 

Java在线生成word excel 文档 -----Springmvc_第2张图片

 

打开文档的时候需要注册,这是一个试用的序列号

IMTG6-BSXJ-JGZ6-3BIWM

 

转载于:https://my.oschina.net/u/3507515/blog/2218592

你可能感兴趣的:(Java在线生成word excel 文档 -----Springmvc)