作者:乔山办公网日期:
返回目录:excel表格制作
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
if request("action")=1 then
Response.ContentType="application/ms-excel"
Response.AddHeader "content-disposition","attachment;filename=/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http:///1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
table {
border-top:1px solid #003399;
border-left:1px solid #003399;
}
td {
border-right:1px solid #003399;
border-bottom:1px solid #003399;
}
thead {
background-color:#000066;
font-weight:bold;
padding:5px;
color:#FFFFFF;
}
</style>
<script language="javascript">
function tableToExcel(){
location.href='?action=1';
}
</script>
</head>
<body>
<input type="button" value="导出数据" onclick="tableToExcel()" />
<%
ConnStr="..."
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
set rs = server.CreateObject("adodb.recordset")
rs.open "select top 10 * from [你的表名]",conn,1,1
if not (rs.eof and rs.bof) then
column = rs.fields.count
response.Write("<table cellpadding='0' cellspacing='0'>")
response.Write("<thead><td>序号</td>")
for each f in rs.fields
response.Write("<td>" & f.name & "</td>")
next
response.Write("</thead>")
for j = 1 to rs.recordcount
if j > 5 then '在第五条的时候隐藏数据,经过测试如果是display为none的数7a686964616fe4b893e5b19e333据是不会导出来的
response.Write("<tr style='display:none'>")
else
response.Write("<tr>")
end if
response.Write("<td>" & j & "</td>")
for i = 0 to column - 1
response.Write("<td>" & rs(i) & "</td>")
next
response.Write("</tr>")
rs.movenext
next
response.Write("</table>")
end if
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
</body>
</html>
提交用户选中的简历ID,进入下面这个页面,根据简历ID号查询数据库7a64e4b893e5b19e333
顶部加入Response.ContentType = "application/vnd.ms-excel" 这行代码,指明这是excel文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "content-disposition", "inline; filename = ASP_Excel.xls"
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Untitled Document</title>
</head>
<body>
<p>asgagsah</p>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td width="30%" bgcolor="#CCCCCC">sdafsagsgdsgds</td>
<td bgcolor="#FFFFFF">sdafsagsgdsgdssdafsagsgdsgdssdafsagsgdsgdssdafsagsgdsg
dssdafsagsgdsgdssdafsagsgdsgdssdafsagsgdsgdssdafsagsgdsgdssdafsagsgdsgds</td>
</tr>
<tr>
<td width="30%" bgcolor="#CCCCCC">sdgdsagdsgdsgsd</td>
<td bgcolor="#FFFFFF">sdafsagsgdsgds</td>
</tr>
<tr>
<td width="30%" bgcolor="#CCCCCC"> </td>
<td bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="30%" bgcolor="#CCCCCC">sdgdssdgdsdsg</td>
<td bgcolor="#FFFFFF">sfsafsddsgsd</td>
</tr>
</table>
<p>fsddssadgsa<img src="joyren/images/ADD.JPG" width="12" height="24">dgsdgds<img src="joyren/images/back_green.jpg" width="842" height="50"></p>
<table width="70%" border="0" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td bgcolor="#CCCCCC">sfsadfsadfdsag</td>
<td bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#CCCCCC">gasdgsdagsgs</td>
<td bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#CCCCCC">sdgsddsgsgs</td>
<td bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#CCCCCC">sdgsdgdsgsgsgdsadgsagsd</td>
<td bgcolor="#FFFFFF"> </td>
</tr>
</table>
<p> </p>
<p>sdsaddsagsddsgds</p>
</body>
</html>
asp导出到excel
在开头加上这一句
Response.ContentType = "application/vnd.ms-excel"
如果导出结果为空白的,那就去掉它
一下是导出Excel代码
--------------------------------------------------------------------------------
<%
set rs=server.createobject("adodb.recordset")
sql="select * from provinceinfo where 1=1"
rs.open sql,objconn,1,1
Set ExcelApp =CreateObject("Excel.Application")
ExcelApp.Application.Visible = True
Set ExcelBook = ExcelApp.Workbooks.Add
ExcelBook.WorkSheets(1).cells(1,1).value ="用户表"
ExcelBook.WorkSheets(1).cells(2,1).value = "用户编号"
ExcelBook.WorkSheets(1).cells(2,2).value = "登陆名"
ExcelBook.WorkSheets(1).cells(2,3).value = "真实姓名"
ExcelBook.WorkSheets(1).cells(2,4).value = "密码"
cnt =3
do while not rs.eof
ExcelBook.WorkSheets(1).cells(cnt,1).value = rs("provinceid")
ExcelBook.WorkSheets(1).cells(cnt,2).value = rs("province")
ExcelBook.WorkSheets(1).cells(cnt,3).value = rs("flag")
ExcelBook.WorkSheets(1).cells(cnt,4).value = rs("id")
rs.movenext
cnt = cint(cnt) + 1
loop
Excelbook.SaveAs "d:\yourfile.xls" '这个是数据导出完毕以后在D盘存成文件e799bee5baa6e997aee7ad94e78988e69d83363
ExcelApp.Application.Quit '导出以后退出Excel
Set ExcelApp = Nothing '注销Excel对象
%>
因你数据量大 另提示EXCEL相关信息
Excel 07-2003一个工作表最多可有65536行,行用数字1—65536表示;最多可有256列,列用英文字母A—Z,AA—AZ,BA—BZ,……,IA—IV表示;一个工作簿中最多含有255个工作表,默认情况下是三个工作表;
Excel 2007及以后版本,一个工作表最多可有1048576行,16384列;
所以建议用2007以上版本的excel