当前页面: 开发资料首页 → J2EE 专题 → 把本页内容导出成word文件或excel文件(原创)
摘要: 如何把本页内容导出成word文件或者excel文件?本文给出了一种方案.并提供了源代码..
/**************************************************
作者:云凤生(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" onclick="unload_word(location.href)" >
<input type="button" value="导出为Excel文档" name="download" onclick="unload_excel(location.href)" >
**************************************************/
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;
}
<%
response.setHeader("Content-disposition","attachment; filename=print_tmp.xls");
%>
<%@ page contentType="application/vnd.ms-excel; charset=gb2312"%>
<%@ page import="java.net.URL"%>
<%
String url_target = new String(request.getParameter("url"));
String filename = new String();
URL url = new URL(url_target);
filename = url.getFile();
%>
<%
response.setHeader("Content-disposition","attachment; filename=print_tmp.doc");
%>
<%@ page contentType="application/vnd.ms-word; charset=gb2312"%>
<%@ page import="java.net.URL"%>
<%
String url_target = new String(request.getParameter("url"));
String filename = new String();
URL url = new URL(url_target);
filename = url.getFile();
%>