Skip to content
Back to formatted view

Raw Message

Message-ID: <23760912.post@talk.nabble.com>
Date: 2009-05-28T12:40:09Z
From: Dieter Menne
Subject: Re ad & name multiple excel sheets using RODBC
In-Reply-To: <aa16b1390905280434r5a8b9e78g3b8189e247ea9763@mail.gmail.com>

simeon duckworth wrote:
> 
> I'd like to be able to read multiple sheets from an excel workbook and use
> the sheet name to name the resulting dataframe using RODBC.  
> 

In Microsoft theory, something like the below should be ok (note the $), but
never managed to get this to work. The same method works perfectly when you
have name ranges within a spreadsheet.

If you only have the sheet names, you should use package xlsReadWrite which
is rather fast, but has some limitations in the non-commercial version.

Dieter


library(RODBC)
filepath <- "workbook.xlsx"
tabls  = list()
channel <- odbcConnectExcel2007(filepath)
for (i in 1:2)
  tabls[[i]] =  sqlQuery(channel, paste("SELECT * from
[Tabelle",i,"$]",sep=""))
odbcClose(channel) # I prefer an explicit odbcClose, but generic close.RODBC
should work.



-- 
View this message in context: http://www.nabble.com/Read---name-multiple-excel-sheets-using-RODBC-tp23760020p23760912.html
Sent from the R help mailing list archive at Nabble.com.