答案:详见以下代码:
<%
Option Explicit
Sub CheckXlDriver()
On Error Resume NextDim vConnString
Dim oConn, oErrvConnString = "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=NUL:"
' 连接NULSet oConn = CreateObject("ADODB.Connection")
oConn.Open vConnStringFor Each oErr in oConn.Errors
' 如果Excel程序报告"文件创建失败",别担心,这表示它正在正常运行呢
If oErr.NativeError = -5036 Then
Exit Sub
End If
NextResponse.Write " MDAC 供应商或驱动程序不可用,请检查或重新安装!<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.EndEnd 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 IfEnd Function
Function OptionTag(vChoice,vTrue)
Dim vSelected
If vTrue Then
vSelected = "selected"
End If
OptionTag = "<option " & vSelected & ">" & _
Server.HtmlEncode(vChoice) & "</option>" & vbCrLfEnd Function
Function IsChecked(vTrue)
If vTrue Then
IsChecked = "checked"
End If
End FunctionFunction BookOptions(vXlFile)
Dim vServerFolder
Dim oFs, oFolder, oFileDim 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 = NothingEnd Function
Function NamedRangeOptions(oConn, vXlRange, vTableType)
Dim oSchemaRs
Dim vSelectedNamedRangeOptions = OptionTag(Empty, Empty)
If TypeName(oConn) = "Connection" Then
Set oSchemaRs = oConn.OpenSchema(adSchemaTables)Do While 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 FunctionFunction DataTable(oConn, vXlRange, vXlHasHeadings)
On Error Resume Next
Const DB_E_ERRORSINCOMMAND = &H80040E14Dim oRs, oField
Dim vThTag, vThEndTagIf vXlHasHeadings Then
vThTag = "<th>"
vThEndTag = "</th>"
Else
vThTag = "<td>"
vThEndTag = "</td>"
End IfDataTable = "<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>
上一个:asp如何调用Java类?
下一个:如何从数据库中调出个人档案?