|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
缺点:正版成本价格贵(盗版就不说了)、不够安全,大多数服务器用windows系统,没有linux安全excel|数据|数据库clsExport2Excel.asp
<%
类入手下手
ClassclsExport2Excel
声明常量、变量
PrivatestrFilePath,strTitle,strSql,strField,strRows,strCols
PrivatestrCn,strHtml,strPath
PrivateobjDbCn,objRs
PrivateobjXlsApp,objXlsWorkBook,objXlsWorkSheet
PrivatearrField
初始化类
PrivateSubClass_Initialize()
strCn="driver={SQLServer};server=LIUHQ;UID=sa;PWD=sa;Database=MS"
setobjDbCn=server.CreateObject("adodb.connection")
objDbCn.openstrCn
strFilePath="."
strTitle="查询了局"
strRows=2
strCols=1
EndSub
烧毁类
PrivateSubClass_Terminate()
EndSub
属性FilePath
PublicPropertyLetFilePath(value)
strFilePath=value
EndProperty
PublicPropertyGetFilePath()
FilePath=strFilePath
EndProperty
属性Title
PublicPropertyLetTitle(value)
strTitle=value
EndProperty
PublicPropertyGetTitle()
Title=strTitle
EndProperty
属性Sql
PublicPropertyLetSql(value)
strSql=value
EndProperty
PublicPropertyGetSql()
Sql=strSql
EndProperty
属性Field
PublicPropertyLetField(value)
strField=value
EndProperty
PublicPropertyGetField()
Field=strField
EndProperty
属性Rows
PublicPropertyLetRows(value)
strRows=value
EndProperty
PublicPropertyGetRows()
Rows=strRows
EndProperty
属性Cols
PublicPropertyLetCols(value)
strCols=value
EndProperty
PublicPropertyGetCols()
Cols=strCols
EndProperty
PublicFunctionexport2Excel()
ifstrSql=""orstrField=""then
response.write"参数设置毛病,请与办理员接洽!感谢"
response.end
endif
ifright(strFilePath,1)="/"orright(strFilePath,1)=""then
strFilePath=left(strFilePath,len(strFilePath)-1)
endif
ifinstr("/",strFilePath)>0then
strFilePath=replace(strFilePath,"/","")
endif
strFilePath=strFilePath&""
setobjFso=createobject("scripting.filesystemobject")
ifobjFso.FolderExists(server.mappath(strFilePath))=Falsethen
objFso.Createfolder(server.mappath(strFilePath))
endif
strFileName=strFilePath&cstr(createFileName())&".xls"
setobjRs=server.CreateObject("adodb.RecordSet")
objRs.openstrSql,objDbCn,3,3
ifobjRs.recordcount<=0then
strHtml="临时没有任何符合的数据导出,若有疑问,请与办理员接洽!抱愧"
else
setobjXlsApp=server.CreateObject("Excel.Application")
objXlsApp.Visible=false
objXlsApp.WorkBooks.Add
setobjXlsWorkBook=objXlsApp.ActiveWorkBook
setobjXlsWorkSheet=objXlsWorkBook.WorkSheets(1)
objXlsWorkSheet.Cells(1,1).Value=strTitle
arrField=split(strField,"||")
forf=0toUbound(arrField)
objXlsWorkSheet.Cells(2,f+1).Value=arrField(f)
next
forc=1toobjRs.recordcount
forf=0toobjRs.fields.count-1
身份证号码特别处置
ifobjRs.fields(f).name="pm_field_41325"orobjRs.fields(f).name="cardID"then
objXlsWorkSheet.Cells(c+2,f+1).Value=""&objRs.fields(f).value
失业特别处置
elseifobjRs.fields(f).name="JiuYe"then
selectcaseobjRs.fields(f).value
case1
objXlsWorkSheet.Cells(c+2,f+1).Value="是"
case0
objXlsWorkSheet.Cells(c+2,f+1).Value="否"
case-1
objXlsWorkSheet.Cells(c+2,f+1).Value="(未知)"
endselect
else
objXlsWorkSheet.Cells(c+2,f+1).Value=objRs.fields(f).value
endif
next
objRs.movenext
next
objXlsWorkSheet.SaveAsserver.mappath(strFileName)
strHtml="Excel文件已导出乐成,您能够<ahref="&strFileName&"target=_blank>翻开</a>文件并将文件另存到当地目次中!"
objXlsApp.Quit
setobjXlsWorkSheet=nothing
setobjXlsWorkBook=nothing
setobjXlsApp=nothing
endif
objRs.close
setobjRs=nothing
iferr>0then
strHtml="E</p>想法是和程序员的想法不一样的.至于为什么.大家去想一想.跟心理学有关的 |
|