Skip to content
Prev 200727 / 398503 Next

Re ading multiple Excel 2007 files with a loop

Thank you for all of the responses.  They were all very helpful.  The best
response came from a gentleman at Berkeley who suggested I change the
channel statement to that used below:
Mark Miller

Gainesville, Florida




library(RODBC)


setwd("U:/test folder")


fname <- list.files(pattern=".\\.xlsx", full.names = FALSE, recursive =
TRUE, ignore.case = TRUE)

z <- length(fname)

print(z)


for (sp in 1:z) {

channel <- odbcDriverConnect(paste("DRIVER=Microsoft Excel Driver (*.xls,
*.xlsx, *.xlsm, *.xlsb); DBQ=U:\\test folder\\",fname[sp],";
ReadOnly=False",sep=''))
 
sqlTables(channel)

my.data <- sqlFetch(channel, "Sheet1")

print(my.data)

odbcClose(channel)
}