Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2008, 01:45 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel Sheetname

Hi,

I'm uploading files to the server to then put the content into access... but to do so, I need to know the name of the excel sheet for the sql query...

rstExcel.Open "SELECT * FROM [Sheet1$];", cnnExcel, adOpenStatic, adLockPessimistic

THis works, but the data has to be in a sheet called 'Sheet1'... if it has another name, it doesn't work...

How can I get the sheet name?


Reply With Quote
  #2 (permalink)  
Old July 16th, 2008, 09:56 PM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dotnetter_ohio
Default

The trick is the sheet name at the bottom of the Excel file. Excel by default has three sheets (tabs) at the bottom of the .xls document. To find the sheet name, just click on the bottom of it. Whenever I used to upload excel files, I always renamed them something unique and 1 word.

The other thing you can do is use the Access link utility to import the Excel sheet. That will actually allow you to select the individual Excel sheet from the Excel file.

Hopefully this helps, if not, contact me.

http://www.dotnetohio.com
Reply With Quote
  #3 (permalink)  
Old July 17th, 2008, 01:12 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I think what DarkHalf was asking was "How do I *FIND* the name of the sheets in a given 'xls' file?"

In some databases, you can ask the DB what tables it contains. If we consider a ".xls" file to be the moral equivalent of a database, when accessed via the JET OLEDB driver, you'd like to be able to find all the names and schemas of all the "tables" (the sheets).

I was hoping somebody else would answer this, but I am *GUESSING* (purely a guess!!) that if it is possible without actually scripting the Excel object (which is a messy-as-all-get-out task!) then the likely answer will lie in ADOX.

Start here to learn more about ADOX:
http://msdn.microsoft.com/en-us/library/ms803865.aspx
Reply With Quote
  #4 (permalink)  
Old July 17th, 2008, 01:30 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Oh, heck...it's actually a piece of cake.

Here's a demo ASP page:
Code:
<%
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" _
     & "Data Source=" & Server.MapPath ("junk.xls") & ";" _
     & "Extended Properties=""Excel 8.0;HDR=Yes""" 

Set cat = Server.CreateObject("ADOX.Catalog")
cat.ActiveConnection = connstr

Response.Write "Found " & cat.Tables.count & " tables in that XLS file.<p>"
For tnum = 0 To cat.Tables.count - 1
    Set tbl = cat.Tables(tnum)
    Response.Write "Table " & tnum & " is named " & tbl.Name & "<br/>" & vbNewLine
Next
%>
Worked like a charm first time. You could even get the column names of all the columns in each table using ADOX. And more.

Since DarkHalf already *HAS* a connection to the spreadsheet, as demoed by the
   rstExcel.Open "SELECT * FROM [Sheet1$];", cnnExcel, adOpenStatic, adLockPessimistic
code line, he/she could just do
<%
Set cat = Server.CreateObject("ADOX.Catalog")
Set cat.ActiveConnection cnnExecl
%>
and be ready to go.

*******************

DarkHalf: How come you open that spreadsheet with adOpenStatic and adLockPessimistic??? Your comments said you were *READING* from that spreadsheet, so why are you locking it for *WRITE*???

And adOpenStatic would only be needed if you were going to do random record positioning within the rows of the sheet. And even then, the Excel driver won't support that, so you'd need to also specify a client-side cursor.
Reply With Quote
  #5 (permalink)  
Old July 17th, 2008, 08:50 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much Old Pedant, that's exactly what I was looking for to do... Also, thank you for correcting my syntax for my connection string...

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in opening excel file in MS Excel 2000 kallol Visual C++ 0 November 16th, 2007 05:48 AM
ASP to Excel - excel output formatting issue mat41 Classic ASP Professional 0 August 13th, 2006 06:41 AM
write multi-sheet Excel w/o Excel.Application manmoth Classic ASP Components 2 November 22nd, 2005 10:56 AM
Delete sheet IF sheetname doesnt contain string crmpicco Excel VBA 3 May 11th, 2005 05:34 AM
Excel in win 2000 to excel winxp (excel 2002) Max Excel VBA 3 August 28th, 2003 04:44 AM



All times are GMT -4. The time now is 02:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.