28,406
社区成员
发帖
与我相关
我的任务
分享
<%
if request.querystring("action")="toExcel" then
Response.ContentType="application/vnd.ms-excel"
Response.AddHeader "content-disposition","attachment;filename=aaa.xls"
end if
%>
<html>
<body>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td> <strong>职务 </strong> </td>
<td> 职级 </td>
<td height="300" width="300"> <img src="http://localhost/images/031.png"/> 这个地方一定要用全路径 </td>
</tr>
</table>
<input type="button" name="out_excel" onClick="location.href='?action=toExcel'" value="导出到excel">
</body>
</html>
<script language= "javascript ">
function exportExcel(atblData)
{
if (typeof(EXPORT_OBJECT)!= "object ")
{
document.body.insertAdjacentHTML( "afterBegin ", " <OBJECT
style= 'display:none ' classid=clsid:0002E510-0000-0000-C000-000000000046
id=EXPORT_OBJECT> </Object> ");
}
with (EXPORT_OBJECT){
DataType = "HTMLData ";
HTMLData =atblData.outerHTML;
try{
ActiveSheet.Export( "C:\\sortTEL.xls ",0);
alert( '导出EXCEL文档完毕 ');
}
catch (e)
{
alert( '导出Excel表失败或您取消了操作! ');
}
}
}
</script>
<table id= "tblData " border= "1 ">
<tr>
<td> A </td>
<td> B </td>
<td> C </td>
<td> D </td>
</tr>
</table>
<center> <input type= "button " value= "导出以上数据为Excel文档 "
onclick= "exportExcel(tblData) "> </center>
<title> 查询导出 </title>
<link href= "../css.css " rel= "stylesheet " type= "text/css " />
<!--#include file= "../inc/conn.asp "-->
<%
dim s,sql,filename,fs,myfile,x
Set fs = server.CreateObject( "scripting.filesystemobject ")
'--假设你想让生成的EXCEL文件做如下的存放
filename = Server.MapPath( "易耗品分类一览表.xls ")
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filename) then
fs.DeleteFile(filename)
end if
'--创建EXCEL文件
set myfile = fs.CreateTextFile(filename,true)
dim trLine,responsestr
strLine = "易耗品编号 " & chr(9) & "易耗名称 " & chr(9) & "阈值 " & chr(9) & "库存 " & chr(9) & "库存金额 "
'--将表的列名先写入EXCEL
myfile.writeline strLine
Set rs = Server.CreateObject( "ADODB.Recordset ")
'--从数据库中把你想放到EXCEL中的数据查出来
idd=request( "id ")
yhse=right(idd,3)
yhfi=left(idd,3)
if yhse= " " then
strsql= "select * from yhid order by yhid asc "
else
strsql= "select * from yhid where yhsecondid= ' "& yhse & " ' and yhfirstid= ' "& yhfi & " ' order by yhid asc "
end if
Set rstData =conn.execute(strSql)
if not rstData.EOF and not rstData.BOF then
Do while Not rstData.EOF
yhname=rstData( "yhname ")
yhid=rstData( "yhfirstid ")&rstData( "yhsecondid ")&rstData( "yhid ")
guoji=rstData( "guoji ")
set rs4 = server.createobject( "adodb.recordset ")
rs4.open "select sum(yhsl),sum(yhmoney) from yhlb where right(yhpianhao,3)= ' " & rstData( "yhid ") & " ' ",conn,1,1
yhkq=rs4(0)
yhmn=rs4(1)
rs4.close
set rs4=nothing
strLine= " "
strLine = " "& yhid & " " & chr(9) & " "& yhname & " " & chr(9) & " "& guoji & " " & chr(9) & " "& yhkq & " " & chr(9) & " "& yhmn & " "
myfile.writeline strLine
rstData.MoveNext
loop
end if
rstData.Close
set rstData = nothing
Conn.Close
Set Conn = nothing
%>
<table width= "400 " height= "100 " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td> <div align= "center "> 已成功导出 </div> </td>
</tr>
<tr>
<td> <div align= "center "> 点击 <a href= "易耗品分类一览表.xls "> 这里 </a> 下载 </div> </td>
</tr>
</table>