ASP Excel worksheet

M

magix

Hi,

If I have following code to read the excel file, how do I validate the
worksheets name ? In code below, if the filename doesn't contains "SomeName"
worksheet, I will need to prompt error.


set oConn = server.createobject("adodb.connection")

oConn.Provider = "Microsoft.Jet.OLEDB.4.0"
oConn.Properties("Extended Properties").Value = "Excel 8.0"
oConn.Open server.mappath("excel/" & request.querystring("filename"))

strCSVFileName1 = "SomeName$"


Thanks.

Regards.
 
J

James Jones

use FSO and check to see if the file exists


Option Explicit

Dim oFSO, message
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(Request.QueryString("filename")) Then
set oConn = server.createobject("adodb.connection") oConn.Provider =
"Microsoft.Jet.OLEDB.4.0"oConn.Properties("Extended Properties").Value =
"Excel 8.0"oConn.Open server.mappath("excel/" &
request.querystring("filename"))strCSVFileName1 = "SomeName$"message = "The
file exists!"Elsemessage = "The file selected does not exists."End If
Set oFSO = Nothing
 
M

magix

I'm not looking for whether the excel file exists or not.
I'm looking into whether the worlsheet called "SomeName$" exists in that
excel file.
 
M

Mike Brind

magix said:
Hi,

If I have following code to read the excel file, how do I validate the
worksheets name ? In code below, if the filename doesn't contains "SomeName"
worksheet, I will need to prompt error.


set oConn = server.createobject("adodb.connection")

oConn.Provider = "Microsoft.Jet.OLEDB.4.0"
oConn.Properties("Extended Properties").Value = "Excel 8.0"
oConn.Open server.mappath("excel/" & request.querystring("filename"))

strCSVFileName1 = "SomeName$"

You can iterate through the worksheets using ADOX thus:

<%
Dim oADOX
Set oADOX = CreateObject("ADOX.Catalog")
oADOX.ActiveConnection = yourconnection
For Each oTable in oADOX.Tables
Response.Write oTable.Name
%>
 
M

Mike Brind

Mike said:
You can iterate through the worksheets using ADOX thus:

<%
Dim oADOX
Set oADOX = CreateObject("ADOX.Catalog")
oADOX.ActiveConnection = yourconnection
For Each oTable in oADOX.Tables
Response.Write oTable.Name
%>

Ah. My "Next" fell below my sig.

Should have read:

<%
Dim oADOX
Set oADOX = CreateObject("ADOX.Catalog")
oADOX.ActiveConnection = yourconnection
For Each oTable in oADOX.Tables
Response.Write oTable.Name
Next
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top