- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通过 ADODB.Connection 读取 Excel(xls 和 xlsx)中的第二行作为列标题时,如何使用它???
' ---------------------------------------------------------------------
' 1. Client uploads Excel
' ---------------------------------------------------------------------
xlsfolder = "D:\website\excels\"
filename = request("filename_from_asp_upload_form")
xlsfile = xlsfolder & filename
' ---------------------------------------------------------------------
' 2. Create backup copy as "original"
' ---------------------------------------------------------------------
dim fscopy
set fscopy=Server.CreateObject("Scripting.FileSystemObject")
exceltypelower = fscopy.GetExtensionName(xlsfile)
replace_text = "_BACKUP." & exceltypelower
xlsfile_copy = replace(xlsfile, ("." & exceltypelower), replace_text)
fscopy.CopyFile xlsfile,xlsfile_copy
set fscopy=nothing
' ---------------------------------------------------------------------
' EXTRA STEP - SELECT EXCEL DRIVER
' ---------------------------------------------------------------------
if exceltype = "XLS" then
exceldriver = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xlsfile & ";Extended Properties=""Excel 8.0;"""
elseif exceltype = "XLSX" then
exceldriver = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & xlsfile & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
exceldriver2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & xlsfile & ";Extended Properties=""Excel 8.0;HDR=No;"""
'*** Second driver allows first row to be read as data and not header allowing Excel cells to be overwritten
else
'**** default to 97-2003 format. ELSE just in case
exceldriver = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xlsfile & ";Extended Properties=""Excel 8.0;"""
end if
' ---------------------------------------------------------------------
' 3. Open and Read first 2 rows of Excel
' 4. Overwrite row 1 with values from row 2
' ---------------------------------------------------------------------
' NOTE: There is another step at UPLOAD that the user flags what kind of Excel Report it is.
' Since there are just a few now, I have the skip_title variable hard-coded
' IF SKIP_TITLE = "Y"... that means the column headers are on row 2
' IF SKIP_TITLE = "N"... that means the column headers are on row 1 and this is unnecessary
' ---------------------------------------------------------------------
if skip_title = "Y" then
excel_query2 = "Select * from [Sheet1$] "
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConn.Open (exceldriver2)
objRecordset.CursorLocation = adUseClient
objRecordset.Open excel_query2 , objConn, adOpenStatic, adLockOptimistic
counter = 1
headcount = 0
colcount = objRecordSet.Fields.Count ' How many columns there are to traverse
p = objRecordSet.GetRows(colcount,0) ' Write excel_query2 results for number of columns above
objRecordSet.MoveFirst
do until objRecordSet.EOF or counter = 0
for each x in objRecordSet.Fields
objRecordSet.Fields(headcount).Value = p(headcount, 1) 'overwrite row 1 with row 2
headcount = headcount + 1
next
counter = counter - 1
objRecordSet.MoveNext
loop
objRecordSet.Update
objRecordset.Close
objConn.Close
end if
' ---------------------------------------------------------------------
' 5. The first 2 rows are now identical
' 6. Close and Re-Open Excel
' ---------------------------------------------------------------------
set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open (exceldriver)
' ---------------------------------------------------------------------
' 7. Select everything except values that equal name of column names
' -e.g. Select column1, column2, column3... from [Sheet1$] where ucase(column1) <> 'COLUMN1'
' ---------------------------------------------------------------------
excel_query = "Select column1, column2, column3... from [Sheet1$] where ucase(column1) <> 'COLUMN1' " 'example
set objRS = objConnection.execute(excel_query)
' ---------------------------------------------------------------------
' 8. Read Excel and Print HTML
' ---------------------------------------------------------------------
response.write "<table><thead><tr>"
for each x in objRS.Fields
response.write("<th>" & ucase(x.name) & "</th>")
next
response.write "</tr></thead>"
response.write "<tbody>"
do until objRS.EOF
response.write "<tr>"
for each fld in objRS.Fields
response.write "<td>" & fld.value & "</td>"
next
response.write "</tr>"
objRS.MoveNext
loop
objRS.close
objConnection.Close
response.write "</tbody></table>"
' ---------------------------------------------------------------------
' Le Fin or Da End
最佳答案
Sub Test22()
Dim cn As New ADODB.Connection
Dim rsT As New ADODB.Recordset
Dim numCols As Long, numRows As Long, x As Long
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & ThisWorkbook.Path & _
"\ADOXSource.xls;Extended Properties=Excel 8.0;"
.CursorLocation = adUseClient
.Open
End With
'read the whole sheet
rsT.Open "select * from [Sheet1$]", cn
rsT.MoveLast
'get # of rows/cols
numCols = rsT.Fields.Count
numRows = rsT.RecordCount
rsT.Close
'get data from specific range
rsT.Open "select * from [Sheet1$A2:" & Chr(64 + numCols) & (numRows - 1) & "]", cn
'I'm testing this in excel...
For x = 0 To rsT.Fields.Count - 1
Sheet1.Range("a1").Offset(0, x).Value = rsT.Fields(x).Name
Next x
Sheet1.Range("a2").CopyFromRecordset rsT
End Sub
关于ASP Classic 中的 Excel ADO - 返回第 2 行作为标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18624416/
我想知道是否有人可以帮助我,因为我对我认为导致简单错误的简单原因视而不见。 我有这个代码: doRound1(x1) denom1 = 5 y1 = denom1 - x1 mod deno
我有以下代码,注释详细说明了会发生什么: averageNum = myArray2(0) 'assign variable response.write(TypeName(averageNum)&"
我有以下脚本,它在本地运行良好(Windows 10 IIS、Windows 2003 Server),但不适用于我们的托管服务器(Windows 2003 Server)。任何超过 4mb 的下载都
ASP Classic 是否具有等同于 PHP 的“包含一次”功能的功能? 最佳答案 我知道这是一个古老的话题,但我想如果有人感兴趣,我会加上我的两分钱。 我编写了一个函数,它完全符合您的要求:无论调
我在Windows 7中运行IIS 7.5,并且已经进入“打开或关闭Windows功能”并在“Internet信息服务/万维网服务/应用程序开发功能”中启用了ASP。一旦做完,我开始收到一个HTTP
我正在尝试从 MS Access 数据库创建一个 ID(主键和自动增量)以用作登录密码。但我收到此错误: Microsoft OLE DB Provider for ODBC Drivers erro
我已经为 Classic ASP(VBScript) + firephp 编写了一个开源调试类,想知道是否可以获取传递给函数的变量的名称?我进行了搜索,但似乎找不到任何技巧来执行此操作。 例子 代码:
我正在尝试从 MS Access 数据库中创建一个 ID(主键和自动增量)以用作登录密码。但是我收到了这个错误: Microsoft OLE DB Provider for ODBC Drivers
我有一个结帐表格,其中产品的数量可以是“n”。那么我如何知道表单中有多少输入字段并从中获取输入呢? 谢谢 最佳答案 如果它是一组单个控件 - 比如说代表项目的可变数量的复选框 - 解决方案非常简单。对
我刚刚审查了一些旧代码并发现了以下内容(在 foo.asp 中): Const ASP_FILENAME = "foo.asp" ' TODO: Update this to the name of
关注 my last question有谁知道如何在经典 ASP 的应用程序范围内使用字典对象?您不能使用 Scripting.Dictionary - 如果您尝试使用,您将看到类似以下内容: App
我的意思是,像 php'h 包括... 就像是 my_file_to_be_included = "include_me.asp" --> 就我目前所见,有几种选择,但每一种都有某种缺点......
我在哪里可以找到“经典”ASP 代码的编辑器? 最佳答案 如果我要进行大量更改,我总是使用 VS2008(支持智能感知、高亮显示和来自 SP1 的调试),Notepad2对于快速(没有智能感知,只有突
例如,我如何运行下面的 me.test? myvar = 'test' me.myvar ASP 查找方法“myvar”但没有找到。在 PHP 中我可以简单地说 $me->$myvar 但 ASP 的
这是要点: 我有一个我想用asp打的电话,我不关心响应。我只想触发调用,我不希望页面等待响应。根据文档,它应该看起来像这样: dim xmlhttp : set xmlhttp = Server.Cr
示例代码: Dim myObject Set myObject = JSON.parse(someJsonResponseFromTheServer) myFunction(myObject.s
据我所知,VBScript/Classic ASP 中唯一的预处理指令是#include。我不知道这是否是正式名称,但我基本上是在寻找可以在通用 VBScript 之前执行代码或其他指令的代码。 VB
据我所知,VBScript/Classic ASP 中唯一的预处理指令是#include。我不知道这是否是正式名称,但我基本上是在寻找可以在通用 VBScript 之前执行代码或其他指令的代码。 VB
我必须维护一个 ASP 3.0 网站... 我想保护sql语句。 我可以使用此代码保护的选择语句: set cmd = Server.createObject("adodb.command") cmd
我正在使用 WebMatrix 中托管的经典 ASP Web 应用程序。有没有办法调试托管在 WebMatrix 中的网站? 最佳答案 WebMatrix 通过调试工具提供很少(没有)。您可以 Res
我是一名优秀的程序员,十分优秀!