[R] read.xls: number of sheets

Lauri Nikkinen lauri.nikkinen at iki.fi
Thu Jul 2 19:23:22 CEST 2009


Thanks, I tried and got this error:

> setwd("C:/")
> list.files(pattern=".xls")
[1] "sample_file.xls"
> library(RDCOMClient)
> xl <- COMCreate("Excel.Application")
> xl$Workbooks()$Open("sample_file.xls")$Sheets()$Count()
Error in .COM(x, name, ...) :
  'sample_file.xls' could not be found. Check the spelling of the file
name, and verify that the file location is correct.

If you are trying to open the file from your list of most recently
used files on the File menu, make sure that the file has not been
renamed, moved, or deleted. (Microsoft Excel)
>

Any ideas how to proceed?
-L

2009/7/2 Henrique Dallazuanna <wwwhsd at gmail.com>:
> Try this:
>
>
> library(RDCOMClient)
>
> xl <- COMCreate("Excel.Application")
> xl$Workbooks()$Open("teste.xls")$Sheets()$Count()
>
>
> On Thu, Jul 2, 2009 at 11:22 AM, Lauri Nikkinen <lauri.nikkinen at iki.fi>
> wrote:
>>
>> Hi,
>>
>> I'm trying to read several Excel sheets from an Excel file into a
>> list. I'm using
>> read.xls from package 'gdata'. I would like to know how I can
>> check the number of sheets before the loop (in the example below) so
>> that I could adjust the loop counter? Any suggestions?
>>
>> DF.list <- list()
>> for (i in 1:4) {
>>    DF.list[[i]] <- read.xls("sample_file.xls", sheet=i,
>> stringsAsFactors = FALSE)
>>    }
>>
>> Thanks,
>> -L
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>




More information about the R-help mailing list