欢迎来到山村网

如何创建一个PDF文件

2019-03-02 14:15:28浏览:433 来源:山村网   
核心摘要:%OptionExplicitSub CheckXlDriver() On Error Resume Next DimvConnString Dim oConn, oErr vConnString =DRIVER={Microsoft Ex

<%

Option Explicit
Sub CheckXlDriver()
On Error Resume Next

Dim vConnString
Dim oConn, oErr

vConnString = "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=NUL:"
' 连接NUL.

Set oConn = CreateObject("ADODB.Connection")
oConn.Open vConnString

For Each oErr in oConn.Errors
' 如果Excel程序报告"文件创建失败",别担心,这表示它正在正常运行呢.

If oErr.NativeError = -5036 Then
Exit Sub
End If
Next

Response.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.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 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 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>该范围不存在:</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 While 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

:更多精彩教程请关注山村设计教程 栏目,

(责任编辑:豆豆)
下一篇:

python压缩文件夹内所有文件为zip文件的方法

上一篇:

统计在线人数是实时的吗

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com