<%
Option Explicit
Sub Checkxldriver ()
On Error Resume Next
Dim vconnstring
Dim oconn, Oerr
vconnstring = "Driver={microsoft Excel DRIVER (*.xls)};D Bq=nul:"
'Connect NUL.
Set oconn = CreateObject ("ADODB. Connection ")
oConn.Open vconnstring
For each oerr in Oconn.errors
' if the Excel program reports ' file creation failed ', don't worry, it means it's working .
If oerr.nativeerror = -5036 Then
Exit Sub
End If
Next
Response.Write "MDACVendor or driver not available,Please check or reinstall!<br><br> "
Response.Write Hex (Err.Number) & "" & Err.Description & "<br>"
For each oerr in Oconn.errors
Response.Write Hex (Oerr.number) & "" & Oerr.nativeerror & "&
Oerr.description & "<br>"
Next
Response.End
End Sub
Function getconnection (vconnstring)
On Error Resume Next
Set getconnection = Server.CreateObject ("ADODB. Connection ")
Getconnection.open vconnstring
If err.number <> 0 Then
Set getconnection = Nothing
End If
End Function
Function Optiontag (vchoice,vtrue)
Dim vselected
If vtrue Then
vselected = "Selected"
End If
Optiontag = "<option" & vselected & ">" & _
Server.HTMLEncode (Vchoice) & "</option>" & VbCrLf
End Function
Function ischecked (vtrue)
If vtrue Then
ischecked = "Checked"
End If
End Function
Function bookoptions (Vxlfile)
Dim Vserverfolder
Dim oFs, Ofolder, ofile
Dim vselected
Vserverfolder = Server.MapPath (".")
Set oFs = Server.CreateObject ("Scripting.FileSystemObject")
Set ofolder = Ofs.getfolder (Vserverfolder)
For each ofile in Ofolder.files
If ofile.type = "Microsoft Excel Worksheet" Then
vselected = (Ofile.name = vxlfile)
Bookoptions = Bookoptions & _
Optiontag (Ofile.name, vselected)
End If
Next
Set ofolder = Nothing
Set OFs = Nothing
End Function
Function namedrangeoptions (oconn, Vxlrange, Vtabletype)
Dim Oschemars
Dim vselected
Namedrangeoptions = Optiontag (Empty, Empty)
If TypeName (oconn) = "Connection" Then
Set oschemars = Oconn.openschema (adSchemaTables)
Do as not oschemars.eof
If oschemars ("table_type") = Vtabletype Then
vselected = (Oschemars ("table_name") = Vxlrange)
Namedrangeoptions = Namedrangeoptions & _
Optiontag (Oschemars ("table_name"), vselected)
End If
Oschemars.movenext
Loop
End If
End Function
Function DataTable (oconn, Vxlrange, vxlhasheadings)
On Error Resume Next
Const Db_e_errorsincommand = &h80040e14
Dim ORs, Ofield
Dim Vthtag, Vthendtag
If vxlhasheadings Then
Vthtag = "<th>"
Vthendtag = "</th>"
Else
Vthtag = "<td>"
Vthendtag = "</td>"
End If
DataTable = "<table border=1>"
If TypeName (oconn) = "Connection" Then
Set oRs = Oconn.execute ("[" & Vxlrange & "]")
If oConn.Errors.Count > 0 Then
For each oconnerr in Oconn.errors
If Oconnerr.number = Db_e_errorsincommand Then
DataTable = DataTable & _
"<tr><td>The range does not exist:</td><th> "& Vxlrange &" </th></tr> "
Else
DataTable = DataTable & _
"<tr><td>" & oconnerr.description & "</td></tr>"
End If
Next
Else
DataTable = DataTable & "<tr>"
For each ofield in Ors.fields
DataTable = DataTable & Vthtag & Ofield.name & Vthendtag
Next
DataTable = DataTable & "</tr>"
Do as not ors.eof
DataTable = DataTable & "<tr>"
For each ofield in Ors.fields
DataTable = DataTable & "<td>" & Ofield.value & "</td>"
Next
DataTable = DataTable & "</tr>"
Ors.movenext
Loop
End If
[1] [2] Next page