Chitika

Thursday, November 3, 2011

ASP/VBS reading excel file

Following is the code to read excel file, inspired from http://forums.aspfree.com/code-bank-54/classic-asp-read-excel-file-into-recordset-141448.html

Dim objConnXls, objRSXls, strSQLXls

Set objConnXls = Server.CreateObject("ADODB.Connection")
objConnXls.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=NO; "& _
"Excel 8.0; DBQ=" & fullName & "; "
           
strSQLXls = "select * from [data]"

set objRSXls = objConnXls.Execute(strSQLXls)

'Fields can be processed as follows:

Dim username, userpassword, firstname, lastname, gender, profession_id, email, dob, country
                   
 username = objRSXls.Fields(0).value
 userpassword = objRSXls.Fields(1).value
 firstname = objRSXls.Fields(2).value
 lastname = objRSXls.Fields(3).value
 gender = objRSXls.Fields(4).value
 profession_id = objRSXls.Fields(5).value
 email = objRSXls.Fields(6).value
 dob = objRSXls.Fields(7).value
 country = objRSXls.Fields(8).value

objRSXls.Close

No comments:

Post a Comment