Set rs2=Server.CreateObject(ADODB.recordset)
sql=select * from eq where eqbumen='&dep&' order by eqbumen desc
rs2.open sql,conn,1,1
set objExcel=CreateObject(Excel.Application)
objExcel.Workbooks.Open(server.mappath(\test)&\book1.xlt) '打开Excel模板
objExcel.Sheets(1).select '选中工作页
set sheetActive=objExcel.ActiveWorkbook.ActiveSheet
num=2 '从Excel的第2行开始
Do while not rs2.eof '循环直至数据集中的数据写完
strRange=b#&:k# '设定要填写内容的单元区域
sheetActive.range(strRange).font.size=10 '设定字体大小
sheetActive.range(strRange).WrapText=false '设定文字回卷
sheetActive.range(strRange).ShrinkToFit=true '设定是否自动适应表格单元大小
sheetActive.range(strRange).value=array(rs2(zcid),rs2(eqname),rs2(eqchangjia),rs2(eqxinghao),rs2(eqnengli),rs2(eqweizhi),rs2(eqxianzhuang),rs2(eqno),rs2(eqbumen),rs2(eqchejian)) '把数据集中的数据填写到相应的单元中
num=num+1
rs2.MoveNext
loop
function getTemporaryFile(myFileSystem)
dim tempFile,dotPos
tempFile=myFileSystem.getTempName
dotPos=instr(1,tempFile,.)
getTemporaryFile=mid(tempFile,1,dotPos)&xlsend function
set myFs=createObject(scripting.FileSystemObject)
filePos=server.mappath(\test)&\temp '要存放打印临时文件的临时目录
fileName=getTemporaryFile(myFs) '取得一个临时文件名
'myFs.DeleteFile filePos&*.xls '删除该目录下所有原先产生的临时打印文件
set myFs=nothing
objExcel.ActiveWorkbook.saveas filePos&filename
objExcel.quit
set objExcel=Nothing。
<%'建立数据库连接
Dim ConnStr, Conn
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0Data Source=" &Server.MapPath("./user.mdb")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnStr
'数据库数据查询
Dim sql, rs
sql = "Select * From info"
Set rs = Server.CreateObject("Adodb.Recordset")
rs.Open sql, Conn, 1, 1
'下面是数据输出
Response.Write("<table width='100%' border='0' cellpadding='0' cellspacing='0'>") &vbCrLf
Response.Write(" <tr>") &vbCrLf
Response.Write("<td height='30'>id</td>") &vbCrLf
Response.Write("<td>username</td>") &vbCrLf
Response.Write("<td>password</td>") &vbCrLf
Response.Write("<td>sex</td>") &vbCrLf
Response.Write("<td>personalinfo</td>") &vbCrLf
Response.Write("<td>ntime</td>") &vbCrLf
Response.Write(" </tr>") &vbCrLf
If rs.BOF And rs.EOF Then
Response.Write("查无数据!")
Else
Do While Not rs.EOF
Response.Write(" <tr>") &vbCrLf
Response.Write("<td height='30'>" &rs("id") &"</td>") &vbCrLf
Response.Write("<td>" &rs("username") &"</td>") &vbCrLf
Response.Write("<td>" &rs("password") &"</td>") &vbCrLf
Response.Write("<td>" &rs("sex") &"</td>") &vbCrLf
Response.Write("<td>" &rs("personalinfo") &"</td>") &vbCrLf
Response.Write("<td>" &rs("ntime") &"</td>") &vbCrLf
Response.Write(" </tr>") &vbCrLf
rs.MoveNext
Loop
End If
Response.Write("</table>") &vbCrLf
'关闭数据库
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
%>
这是全部代码,认真仔细的研究每一句代码,能全部理解的话 那asp基本就等于入门了 加油!:)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)