|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Accessing Excel cells from ASP/VBScript
I posted this in the ASP Development forum to no avail - I'm thinking this may be more of a VBA thing...
I'm trying to grab cell values from an excel file using ASP with VBScript. This is the code I'm using: Code:
<%
Set ExcelConn = Server.CreateObject("ADODB.Connection")
Set ExcelRS = Server.CreateObject("ADODB.Recordset")
ExcelConn.Provider = "Microsoft.Jet.OLEDB.4.0"
ExcelConn.Properties("Extended Properties").Value = "Excel 8.0"
ExcelConn.Open "c:\inetpub\wwwroot\asp\calendar\test.xls"
set ExcelRS = ExcelConn.Execute ("SELECT * FROM [Sheet1$]")
Response.Write(ExcelRS(1,1))
%>
I've tried Response.write(ExcelRS($A$1)) and every other variation I can think of. What is the syntax for refering to a cell location from VBScript/VBA/etc... ? |
|
#2
|
||||
|
||||
|
Try with
Response.write(ExcelRs(0)) --- for referring to first column of excel sheet and similarly u can fetch values for different columns Quote:
|
|
#3
|
|||
|
|||
|
Thanks, HiThere... but that gets me row 2 (A2, B2, etc.). How do I get to the other rows? I've tried about every number from 0 to 260, and once I get past 3 (D2, the last cell in row 2), I get:
"Item cannot be found in the collection corresponding to the requested name or ordinal." Am I brain dead, and overlooking something obvious? joe |
|
#4
|
||||
|
||||
|
Use this for looping thru the rows. Here i have used to retreive data from three columns A, B and C
Do until Excelrs.eof msgbox rs(0) msgbox rs(1) msgbox rs(2) rs.movenext Loop I hope this helps u. Hey according to me why it begins from row 2 is because it assumes that row 1 is having column names. If ur excel file doesnot contains columns then use connection string as .ConnectionString = "Data Source=C:\MyFolder\MyWorkbook.xls;" & _ "Extended Properties=Excel 8.0; HDR=No;" Quote:
|
|
#5
|
|||
|
|||
|
Awesome! Just what the doctor ordered...
Thanks, HiThere! |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Accessing Excel cells from ASP/VBScript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|