ASP Excel worksheet

Discussion in 'ASP General' started by magix, Jul 27, 2006.

  1. magix

    magix Guest

    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.
     
    magix, Jul 27, 2006
    #1
    1. Advertising

  2. magix

    James Jones Guest

    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

    hope this helps."magix" <> wrote in message
    news:44c8e1a3$...
    > 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.
    >
     
    James Jones, Jul 27, 2006
    #2
    1. Advertising

  3. magix

    magix Guest

    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.


    "James Jones" <> wrote in message
    news:...
    > 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
    >
    > hope this helps."magix" <> wrote in message
    > news:44c8e1a3$...
    >> 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.
    >>

    >
    >
     
    magix, Jul 27, 2006
    #3
  4. magix

    James Jones Guest

    o ok, lol sorry. i misread your post.

    sorry, im unable to help with that.


    Jay


    http://groups.yahoo.com/groups/classicasp/





    "magix" <> wrote in message
    news:44c8e1a3$...
    > 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.
    >
     
    James Jones, Jul 27, 2006
    #4
  5. magix

    Mike Brind Guest

    magix wrote:
    > 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
    %>

    --
    Mike Brind
    Next
     
    Mike Brind, Jul 27, 2006
    #5
  6. magix

    Mike Brind Guest

    Mike Brind wrote:
    > magix wrote:
    > > 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
    > %>
    >
    > --
    > Mike Brind
    > Next


    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
    %>
     
    Mike Brind, Jul 27, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2hhbyBZb25n?=

    How to delete an Excel worksheet by using ASP.NET?

    =?Utf-8?B?U2hhbyBZb25n?=, May 10, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,147
    Martin Dechev
    May 12, 2004
  2. Steve Kershaw
    Replies:
    2
    Views:
    547
    Cowboy \(Gregory A. Beamer\)
    Jul 16, 2007
  3. sridevi
    Replies:
    3
    Views:
    687
    sridevi
    May 11, 2005
  4. Replies:
    1
    Views:
    304
    Mirco Wahab
    Apr 17, 2007
  5. Katja
    Replies:
    1
    Views:
    226
Loading...

Share This Page