首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > vbScript >

vbscript-页面 打开EXCEL解决思路

2012-03-28 
vbscript-页面 打开EXCEL如何在一个(vbscript) 页面上用一个BUTTON按钮打开一个文件夹里任意一个后续名为.

vbscript-页面 打开EXCEL
如何在一个(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        showXLSEnd 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 = NothingEnd Sub</SCRIPT><INPUT       id="oTxt"      type="text"      CONTENTEDITABLE="false"/><BUTTON onClick="getFile">浏览</BUTTON><DIV id="oDIV"></DIV></BODY></HTML> 

热点排行