dddggg [原作]
Função SwitchExcelInfo(xlsFileName)
Dim xlsStr
Escureça rs
Dim eu, j, k
Dim ExcelConn
Escurecer arquivo Excel
Dim objExcelApp
Dim objExcelBook
Dim bgColor
xlsStr = ""
ExeclFile = Server.MapPath(xlsFileName)
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Quit
Definir objExcelApp = CreateObject("Excel.Application")
objExcelApp.Quit
objExcelApp.DisplayAlerts = false '不显示警告
objExcelApp.Application.Visible = false '不显示界面
objExcelApp.WorkBooks.Open(ExeclFile)
definir objExcelBook = objExcelApp.ActiveWorkBook
reDim arrSheets(objExcelBook.Sheets.Count)
Para i=1 para objExcelBook.Sheets.Count
arrSheets(i) = objExcelBook.Sheets(i).Nome
Próximo
objExcelApp.Quit
Definir objExeclApp = nada
'#################
'Poder Por www.downcodes.com
'#################
Definir ExcelConn = Server.CreateObject("ADODB.Connection")
ExcelDriver = "Driver={Driver Microsoft Excel (*.xls)};DBQ=" & ExeclFile
ExcelConn.Open ExcelDriver
Definir rs = Server.CreateObject("Adodb.RecordSet")
Para i = 1 para UBound(arrSheets)
Sql = "SELECIONE * FROM ["& arrSheets(i) &"$] "
''显示各工作表的名称
''xlsStr = xlsStr & "<br>"& arrSheets(i) &"<br>"
xlsStr = xlsStr & "<table cellpadding=1 width=""100%"" cellpacing=1 border=1 bordercolor='#000000' style='border-collapse:collapse;border:2px solid #000000'>"
rs.Open Sql,ExcelConn,1,1
k = 1
Embora não seja rs.eof
Se k Mod 2 <> 0 Então bgColor = "bgColor=#E0E0E0" Else bgColor = ""
xlsStr = xlsStr & "<tr "& bgColor &">"
xlsStr = xlsStr & "<td>"& rs(0) &"</td>"
Para j = 0 para rs.Fields.Count-1
xlsStr = xlsStr & "<td>"& rs(j) &"</td>"
Próximo
xlsStr = xlsStr & "</tr>"
rs.movnext
k = k + 1
Wend
xlsStr = xlsStr & "</table><br>"
rs.Fechar
Próximo
ExcelConn.Fechar
Definir ExcelConn = Nada
SwitchExcelInfo = xlsStr
Função final