[R] Import range of cells from Excel
David James
dj at research.bell-labs.com
Tue Mar 2 14:48:13 CET 2004
Jean-Noel wrote:
> Dear all,
> I would like to import a range of cells (e.g. F10:K234) from an Excel
> worksheet to R. I have looked for documentation on RODBC and RDCOMClient but
> I was not able to find enough information to solve my problem and all the
> examples I have seen were dealing with an entire worksheet, not a range of
> cells.
In the case of RDCOMClient, you can do:
xls <- COMCreate("Excel.Application")
xls[["Workbooks"]]$Open("Book1.xls")
rng <- xls[["ActiveSheet"]]$Range("F10:K234")
x <- rng[["Value"]]
Depending on what the range contains (e.g., the range consists
of only one data type or not), x may be a list with each element
corresponding to a column in the excel range.
The thing to remember here is how to build ranges -- e.g., use
the Range() method of the worksheet. This, though, is not R specific,
and it's determined by the Excel COM specification.
Regards,
--
David
> Thanks,
>
> Jean-Noel
>
> Jean-Noel Candau
> INRA - Unité de Recherches Forestières Méditerranéennes
> Avenue A. Vivaldi
> 84000 AVIGNON
> Tel: (33) 4 90 13 59 22
> Fax: (33) 4 90 13 59 59
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list