- Code: Select all
Function fillColumnHeaders(filePath)
Dim h as new hashtable
Dim cnExcel As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & filePath & ";Extended Properties=""Excel 8.0;HDR=NO;""")
cnExcel.Open()
Dim lookup = cnExcel.GetOleDbSchemaTable(OleDbSchemaGuid.tables, Nothing)
Dim cmdExcel As New OleDbCommand("SELECT * FROM [" & lookup.rows(0)("TABLE_NAME") & "]", cnExcel)
Dim dr As OleDbDataReader
dr = cmdExcel.ExecuteReader
if dr.read then
Dim strColNum
for x = 0 to lookup.columns.count
strColNum = "col" & x
h.add(strColNum, dr(x))
response.write (x & " " & h("col" & x) & "<br/>")
next
end if
response.write("<br/>" & lookup.columns.count)
cnExcel.Close()
dr.Close()
end function
It will write out the proper header row column names up to 9 (which I can't figure out what that is) and if you look at my for loop, the max is set to "lookup.columns.count" - which is what 9 equates to.... unfortunately my file has 11 columns, not nine. If I do lookup.columns.count + 2 if gets it all which leads me to believe that "lookup.columns.count" is not what I want. It needs to be dynamic, and obviously + 2 doesn't work for all files, just this one. I'm not sure what I need to be retrieving as I figured lookup.columns.count would give me the total columns in row 0 - it doesn't. Clearly I'm making a mistake here but it's not clear to me what, only where.
