delphiadoexcel:ASP中利用ADO显示Excel文件内容的函数

代码如下:

FunctionSwitchExcelInfo(xlsFileName)
’#################
’PowerByxrss.cn
’#################
DimxlsStr
Dimrs
Dimi,j,k
DimExcelConn
DimExcelFile
DimobjExcelApp
DimobjExcelBook
DimbgColor
DimEr

Er=False
xlsStr=\"\"

IfxlsFileName=\"\"Then
Er=True
EndIf

IfEr=FalseANDUCase(Mid(file.fileName,InStrRev(file.filename,\".\"),Len(file.Filename)))<>\"xls\"Then
Er=False
EndIf

IfEr=FalseThen
ExeclFile=Server.MapPath(xlsFileName)
SetobjExcelApp=CreateObject(\"Excel.Application\")
objExcelApp.Quit
SetobjExcelApp=CreateObject(\"Excel.Application\")
objExcelApp.Quit
objExcelApp.DisplayAlerts=false’不显示警告
objExcelApp.Application.Visible=false’不显示界面
objExcelApp.WorkBooks.Open(ExeclFile)
setobjExcelBook=objExcelApp.ActiveWorkBook
reDimarrSheets(objExcelBook.Sheets.Count)
Fori=1toobjExcelBook.Sheets.Count
arrSheets(i)=objExcelBook.Sheets(i).Name
Next
objExcelApp.Quit
SetobjExeclApp=nothing

SetExcelConn=Server.CreateObject(\"ADODB.Connection\")
ExcelDriver=\"Driver={MicrosoftExcelDriver(*.xls)};DBQ=\"&ExeclFile
ExcelConn.OpenExcelDriver
Setrs=Server.CreateObject(\"Adodb.RecordSet\")
Fori=1toUBound(arrSheets)
Sql=\"SELECT*FROM[\"&arrSheets(i)&\"$]\"
’’显示各工作表的名称
’’xlsStr=xlsStr&\"
\"&arrSheets(i)&\"
\"
xlsStr=xlsStr&\"\"
rs.OpenSql,ExcelConn,1,1
k=1
WhileNotrs.eof
IfkMod2<>0ThenbgColor=\"bgColor=#E0E0E0\"ElsebgColor=\"\"
xlsStr=xlsStr&\"\"
xlsStr=xlsStr&\"\"&rs(0)&\"\"
Forj=0tors.Fields.Count-1
xlsStr=xlsStr&\"\"&rs(j)&\"\"
Next
xlsStr=xlsStr&\"\"
rs.movenext
k=k+1
Wend
xlsStr=xlsStr&\" [Page]
\"
rs.Close
Next
ExcelConn.Close
SetExcelConn=Nothing
EndIf
SwitchExcelInfo=xlsStr
EndFunction

Tags:  vbadoexcel adoexcel ado.netexcel delphiadoexcel

延伸阅读

最新评论

发表评论