Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read From Excel file

Status
Not open for further replies.

emblewembl

Programmer
May 16, 2002
171
GB
I am trying to read data from an excel file and use an asp page to iterate through the rows and display the information. I have found an old thread but it doesn't seem to work.... can someone give me an example of opening an excel file, and reading the information out of it using asp?

Thanks! i love chocolate
 
emblewembl,

Set objXL = WScript.CreateObject("EXCEL.application")
' objXL.Visible = True
Set objWkBook = objXL.WorkBooks.Open(Filename)
Set Actv = objWkBook.Worksheets(sheetname)

rows = Actv.rows.Count
cols = Actv.columns.Count

For Irow = 2 to rows
' Read values in column 1
xval = actv.Cells(irow, 1).Value
Next


fengshui_1998
 
Thanks FengShui. I haven't tried it the way you suggested but found the following which works fine for me.
Code:
Dim objConn
Dim objRs
Dim Counter
Dim XLFile
Dim SQL

Set objConn= Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")

'The Excel File Name
XLFile = "C:\Inetpub\[URL unfurl="true"]wwwroot\scgu\excel\test.xls"[/URL]

'The Data to extract
SQL = "Select * from gross"
    
'Create and open the objConnection
objConn.ConnectionString = "DBQ="& XLFile &";DRIVER=Microsoft Excel Driver (*.xls);UID=admin;"
objConn.Open

'open the recordset
objRs.open SQL, objConn

Do While not objRs.EOF
	Response.Write(&quot;<b>&quot; & objRs(&quot;First name&quot;) & &quot;</b><br>&quot;)
	Response.Write(objRs(&quot;last name&quot;) & &quot;<br>&quot;)
	Response.Write(objRs(&quot;club&quot;) & &quot;<br><br>&quot;)
    objRs.Movenext
Loop

Response.Write(&quot;Hello World&quot;)
    
' DisConnect recordset, eliminate objConnection
objRs.close
Set objRs=nothing
objConn.Close
Set objConn=nothing
Does anyone know if either of these is better/worse in times of speed and efficiency? i love chocolate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top