如何在一个(vbscript) 页面上用一个BUTTON按钮打开一个文件夹里任意一个后续名为.xls的EXCEL表格
------解决方案--------------------
好笼统。
- HTML code
<HTML><BODY> <STYLE type="text/css"> table { border-collapse:collapse; border:solid #999; border-width:1px 0 0 1px; } table caption {font-size:14px;font-weight:bolder;} table th,table td {border:solid #999;border-width:0 1px 1px 0;padding:2px;} tfoot td {text-align:center;} </STYLE> <SCRIPT language="VBScript"> '************************************************************************** '获得xls文件 '************************************************************************** Sub getFile On Error Resume Next Set oDialog = CreateObject("UserAccounts.CommonDialog") oDialog.Filter = "xls File|*.xls|All Files|*.*" oDialog.ShowOpen if Err Then Msgbox "错误代码:" & Err.Number & VbCrLf & Err.Description Err.Clear else if Len(Trim(oDialog.FileName)) > 0 then '如果选择了文件 oTxt.value=oDialog.FileName end if end if Set oDialog = Nothing showXLS End Sub '************************************************************************** '显示XLS文件 '************************************************************************** Sub showXLS On Error Resume Next Set oConn = CreateObject("Adodb.Connection") Set oAdox = CreateObject("Adox.Catalog") sConn = "Provider = Microsoft.Jet.Oledb.4.0;" & _ "Data Source = " & oTxt.value & ";" & _ "Extended Properties = ""Excel 8.0; HDR=No"";" sSQL = "Select * From " oConn.Open sConn if Err Then Msgbox "错误代码:" & Err.Number & VbCrLf & Err.Description Err.Clear else oAdox.ActiveConnection = oConn sSQL = sSQL & "[" & oAdox.Tables(0).Name & "]" '为了简便,只处理第一个工作表 Set oRecordSet = oConn.Execute(sSQL) if Err Then Msgbox "错误代码:" & Err.Number & VbCrLf & Err.Description Err.Clear else sHTML = "<table>" 'sHTML = sHTML & "<tr>" 'for each x in oRecordSet.Fields ' sHTML = sHTML & "<td>" & x.Name & "</td>" 'next 'sHTML = sHTML & "</tr>" oRecordSet.MoveFirst Do sHTML = sHTML & "<tr>" for each x in oRecordSet.Fields sHTML = sHTML & "<td>" & oRecordSet.Fields.Item(x.Name) & "</td>" next sHTML = sHTML & "</tr>" oRecordset.MoveNext Loop Until oRecordSet.EOF sHTML = sHTML & "</table>" oDiv.innerHTML = sHTML end if end if Set oRecordSet = Nothing Set oAdox = Nothing Set oConn = Nothing End Sub </SCRIPT> <INPUT id="oTxt" type="text" CONTENTEDITABLE="false" /><BUTTON onClick="getFile">浏览</BUTTON> <DIV id="oDIV"></DIV> </BODY></HTML>