欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

vbscript-页面 打开excel解决思路

更新时间: 2014-01-05 01:52:58 责任编辑: Author_N1

 

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
    
    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> 			
			
		
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 01:52:58
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/2496/
本文WWW.DOC100.NET DOC100.NET版权所有。