WEB开发网
开发学院软件开发Java 把本页内容导出成word文件或excel文件(原创) 阅读

把本页内容导出成word文件或excel文件(原创)

 2007-12-23 12:22:38 来源:WEB开发网   
核心提示:说明:文件unload.js在js目录下,文件unload_Excel.jsp和unload_Word.jsp在unload目录下,把本页内容导出成word文件或excel文件(原创),1,unload.js/**作者:云凤生(hainanyun@hotmail.com)创建日期:2005-1-21最后修改日期:200

  说明:文件unload.js在js目录下,文件unload_Excel.jsp和unload_Word.jsp在unload目录下。

1,unload.js
/**************************************************
作者:云凤生(hainanyun@hotmail.com)
创建日期:2005-1-21
最后修改日期:2005-3-30

Function:
1,unload_word():unload local page as word file
2,unload_excel():unload local page as excel file
3,...(waiting for your additional work)

For example:
1,in the head of Html file,include this file:
<script src="js/unload.js" type="text/javascript"></script>
2,add unload button:
<input type="button" value="导出为Word文档" name="download" >
<input type="button" value="导出为Excel文档" name="download" >
**************************************************/
function unload_word()
{
    var url=location.href;
    location.href='unload/unload_word.jsp?url='+url;
}

function unload_excel()
{
    var url=location.href;
    location.href='unload/unload_excel.jsp?url='+url;
}


2,unload_excel.jsp
<%
  response.setHeader("Content-disposition","attachment; filename=PRint_tmp.xls");
%>
<%@ page contentType="application/vnd.ms-excel; charset=gb2312"%>
<%@ page import="Java.net.URL"%>

<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<%
String url_target = new String(request.getParameter("url"));
String filename = new String();

URL url = new URL(url_target);
filename = url.getFile();
%>

<jsp:include page="<%=filename%>" />


3,unload_word.jsp
<%
  response.setHeader("Content-disposition","attachment; filename=print_tmp.doc");
%>
<%@ page contentType="application/vnd.ms-word; charset=gb2312"%>
<%@ page import="java.net.URL"%>

<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<%
String url_target = new String(request.getParameter("url"));
String filename = new String();

URL url = new URL(url_target);
filename = url.getFile();
%>

<jsp:include page="<%=filename%>" />
进入讨论组讨论。

(出处:http://www.cncms.com)


Tags:内容 导出 word

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接