📄 daochu.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用EXCEL输出</title>
<!--
<%
Class ExcelGen
Private objSpreadsheet
Private iColOffset
Private iRowOffset
Sub Class_Initialize()
Set objSpreadsheet = Server.CreateObject("owc.spreadsheet") '"OWC.Spreadsheet"
iRowOffset = 2
iColOffset = 2
End Sub
Sub Class_Terminate()
Set objSpreadsheet = Nothing 'Clean up
End Sub
Public Property Let ColumnOffset(iColOff)
If iColOff > 0 then
iColOffset = iColOff
Else
iColOffset = 2
End If
End Property
Public Property Let RowOffset(iRowOff)
If iRowOff > 0 then
iRowOffset = iRowOff
Else
iRowOffset = 2
End If
End Property
Sub GenerateWorksheet(objRS)
'Populates the Excel worksheet based on a Recordset"s contents
'Start by displaying the titles
If objRS.EOF then Exit Sub
Dim objField, iCol, iRow
iCol = iColOffset
iRow = iRowOffset
For Each objField in objRS.Fields
objSpreadsheet.Cells(iRow, iCol).Value = objField.Name
objSpreadsheet.Columns(iCol).AutoFitColumns
'设置Excel表里的字体
objSpreadsheet.Cells(iRow, iCol).Font.Bold = True
objSpreadsheet.Cells(iRow, iCol).Font.Italic = False
objSpreadsheet.Cells(iRow, iCol).Font.Size = 10
objSpreadsheet.Cells(iRow, iCol).Halignment = 2 '居中
iCol = iCol + 1
Next 'objField
'Display all of the data
Do While Not objRS.EOF
iRow = iRow + 1
iCol = iColOffset
For Each objField in objRS.Fields
If IsNull(objField.Value) then
objSpreadsheet.Cells(iRow, iCol).Value = ""
Else
objSpreadsheet.Cells(iRow, iCol).Value = objField.Value
objSpreadsheet.Columns(iCol).AutoFitColumns
objSpreadsheet.Cells(iRow, iCol).Font.Bold = False
objSpreadsheet.Cells(iRow, iCol).Font.Italic = False
objSpreadsheet.Cells(iRow, iCol).Font.Size = 10
End If
iCol = iCol + 1
Next 'objField
objRS.MoveNext
Loop
End Sub
Function SaveWorksheet(strFileName)
'Save the worksheet to a specified filename
On Error Resume Next
Call objSpreadsheet.ActiveSheet.Export(strFileName, 0)
SaveWorksheet = (Err.Number = 0)
End Function
End Class
' 获取要显示的字段
bid=request.Form("chid") '序号
chpro=request.Form("chpro")'项目名称
chsf=request.Form("chsf") ' 省份
tname=request.Form("chname")'姓名
chsex=request.Form("chsex") '性别
chsch=request.Form("chsch") '毕业学校名称
'获取条件
txtid=request.Form("txtid")
mname=request.Form("txtname")
txtsex=request.Form("txtsex")
txtsch=request.Form("txtsch")
set newconn=server.createobject("adodb.connection")
set objrs=server.createobject("adodb.recordset")
DBPath = Server.MapPath("#ctm wish.mdb")
newconn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
sqlcmd=sqlcmd+"select "
dim lflag
lflag=0
if bid=1 then
lflag=1
sqlcmd=sqlcmd+" "+"序号"
else
sqlcmd=sqlcmd
end if
if tname=1 and bid=1 then
lflag=1
sqlcmd=sqlcmd+","
sqlcmd=sqlcmd+"姓名"
else if tname=1 then
lflag=1
sqlcmd=sqlcmd+"姓名"
end if
end if
if chpro=1 and lflag=1 then
sqlcmd=sqlcmd+","
sqlcmd=sqlcmd+"项目名称"
else if chpro=1 then
lflag=1
sqlcmd=sqlcmd+"项目名称"
end if
end if
if chsf=1 and lflag=1 then
sqlcmd=sqlcmd+","
sqlcmd=sqlcmd+"省份"
else if chsf=1 then
lflag=1
sqlcmd=sqlcmd+"省份"
end if
end if
if chsex=1 and lflag=1 then
sqlcmd=sqlcmd+","
sqlcmd=sqlcmd+ "性别"
else if chsex=1 then
lflag=1
sqlcmd=sqlcmd+ "性别"
end if
end if
if chsch=1 and lflag=1 then
sqlcmd=sqlcmd+","
sqlcmd=sqlcmd+ "毕业学校名称"
else if chsch=1 then
lflag=1
sqlcmd=sqlcmd+ "毕业学校名称"
end if
end if
sqlcmd=sqlcmd+" "+"from student_info "
dim flag_look '标识为查寻,在多条件下,如果前面已经有一个条件,则为1
flag_look=0
if txtid<>"" then
flag_look=1
sqlcmd=sqlcmd+"where 序号="&txtid
else
flag_look=0
end if
if flag_look=1 and mname<>"" then
sqlcmd=sqlcmd+"and 姓名='"&mname&"'"
else if mname<>""then
sqlcmd=sqlcmd+"where 姓名='"&mname&"'"
flag_look=1
end if
end if
if flag_look=1 and txtsex<>"" then
sqlcmd=sqlcmd+"and 性别='"&txtsex&"'"
else if txtsex<>""then
sqlcmd=sqlcmd+"where 性别='"&txtsex&"'"
flag_look=1
end if
end if
if flag_look=1 and txtsch<>"" then
sqlcmd=sqlcmd+"and 毕业学校名称='"&txtsch&"'"
else if txtsch<>""then
sqlcmd=sqlcmd+"where 毕业学校名称='"&txtsch&"'"
flag_look=1
end if
end if
objrs.Open sqlcmd,newconn,1,2
Dim SaveName
SaveName = Request.Cookies("savename")("name")
Dim objExcel
Dim ExcelPath
ExcelPath = "Excel\11.xls"
Set objExcel = New ExcelGen
objExcel.RowOffset = 1
objExcel.ColumnOffset = 1
objExcel.GenerateWorksheet(objRS)
If objExcel.SaveWorksheet(Server.MapPath(ExcelPath)) then
Response.Write "已保存为Excel文件"
Else
Response.Write "在保存过程中有错误!"
End If
Set objExcel = Nothing
objRS.Close
Set objRS = Nothing
%>
-->
</head>
<body>
<a href="excel/11.xls">下载 excel文件
</a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -