[R] Re ad & name multiple excel sheets using RODBC

Dieter Menne dieter.menne at menne-biomed.de
Thu May 28 14:40:09 CEST 2009




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.




More information about the R-help mailing list