[R] read.xls: number of sheets
William Dunlap
wdunlap at tibco.com
Thu Jul 2 19:48:02 CEST 2009
Try changing "sample_file.xls" to normalizePath("sample_file.xls")
so you are passing an absolute file path to Excel.
Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Lauri Nikkinen
> Sent: Thursday, July 02, 2009 10:23 AM
> To: Henrique Dallazuanna
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] read.xls: number of sheets
>
> 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
> >
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list