这是个变通的方法,事先在EXCEL中的sheet1表中设计好页面尺寸、字体大小、字体颜色等。再把要想填数据的单元格指向sheet2表的的一个单元格,sheet2中这些单元格是通过ASP代码将数据库中的数据读取后写入的。
1、附上我项目中的这个ASP文件paigongdan.asp
<!--#include file="hbwlConfig.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>生成派工单</title>
<link rel="stylesheet" type="text/css" href="images/hbwl.css"/>
<script src="js/jquery1.3.2.js" type="text/javascript"></script>
</head>
<%
Set fso = CreateObject("Scripting.FileSystemObject")
newFileName=Minute(time)&Second(time)&".xls"
f1=Server.MapPath("images/paigongdan.xls")
f2=Server.MapPath("images/tmpGongdan/"&newFileName)
fso.CopyFile f1,f2
%>
<body οnunlοad="$.get('callDelFile.asp?delName=<%=newFileName%>',function(data){});">
<%
Set connxls = Server.CreateObject("ADODB.Connection")
connxls.Open "Driver={Microsoft excel Driver (*.xls)};ReadOnly=False;DBQ=" & Server.MapPath("images/tmpGongdan/"&newFileName)
hbwl.connOpen
id=request.querystring("id")
set rs=hbwl.conn.execute("select 报修单号,客服姓名,派单时间,报修地址,报修人姓名,户主姓名,单位名称1+单位名称2 as 报修人单位,报修人电话,报修类型1+报修类型2 as 报修类型,故障标题,故障描述 from 报修维修 where ID="&id)
for i=0 to rs.fields.count-1
sql="update [Sheet2$] set 字段值='"&rs(i)&"' where 字段名='"& rs(i).name &"'"
connxls.execute(sql)
next
connxls.close
set connxls=nothing
%>
<table width="300" border="0" cellpadding="0" cellspacing="0" class="tableWg" style="margin:50px 100px;">
<tr>
<td id="mainTitle">生成派工单</td>
</tr>
<tr>
<td height="80" align="center" class="red">派工单已成功生成!<a href="images/tmpGongdan/<%=newFileName%>">单击这里可以下载</a></td>
</tr>
</table>
</body>
</html>
2、附上这个EXCEL文件