dddggg [原著]
函數 SwitchExcelInfo(xlsFileName)
變暗xlsStr
暗淡
調暗 i,j,k
昏暗 ExcelConn
昏暗的 Excel 文件
昏暗 objExcelApp
Dim objExcelBook
暗淡 bgColor
xlsStr =“”
ExeclFile = Server.MapPath(xlsFileName)
設定 objExcelApp = CreateObject("Excel.Application")
objExcelApp.退出
設定 objExcelApp = CreateObject("Excel.Application")
objExcelApp.退出
objExcelApp.DisplayAlerts = false '不顯示警告
objExcelApp.Application.Visible = false '不顯示介面
objExcelApp.WorkBooks.Open(ExeclFile)
設定 objExcelBook = objExcelApp.ActiveWorkBook
reDim arrSheets(objExcelBook.Sheets.Count)
對於 i=1 到 objExcelBook.Sheets.Count
arrSheets(i) = objExcelBook.Sheets(i).Name
下一個
objExcelApp.退出
設定 objExeclApp=無
'#################
'由www.downcodes.com提供支持
'#################
設定 ExcelConn = Server.CreateObject("ADODB.Connection")
ExcelDriver = "Driver={Microsoft Excel 驅動程式 (*.xls)};DBQ=" & ExeclFile
ExcelConn.Open ExcelDriver
設定 rs = Server.CreateObject("Adodb.RecordSet")
對於 i = 1 到 UBound(arrSheets)
Sql = "SELECT * FROM ["& arrSheets(i) &"$] "
'' 顯示各工作表的名稱
''xlsStr = xlsStr & "<br>"& arrSheets(i) &"<br>"
xlsStr = xlsStr & "<table cellpadding=1 width=""100%"" cellspacing=1 border=1 bordercolor='#000000' style='border-collapse:collapse;border:2pxsolid #000000'>"
rs.Open Sql,ExcelConn,1,1
k = 1
雖然不是 rs.eof
如果 k Mod 2 <> 0 則 bgColor = "bgColor=#E0E0E0" 否則 bgColor = ""
xlsStr = xlsStr & "<tr "& bgColor &">"
xlsStr = xlsStr & "<td>"& rs(0) &"</td>"
對於 j = 0 到 rs.Fields.Count-1
xlsStr = xlsStr & "<td>"& rs(j) &"</td>"
下一個
xlsStr = xlsStr & "</tr>"
rs.movenext
k = k + 1
文德
xlsStr = xlsStr & "</table><br>"
rs.關閉
下一個
ExcelConn.關閉
設定 ExcelConn = 無
SwitchExcelInfo = xlsStr
結束功能