Skip to content
Prev 173500 / 398506 Next

read.xls and name of worksheet

Here is a program that will get a list of the sheet names and then
read in the indicated name.  Modify to suit.

library(rcom)
xls <- "C:\\test.xls"
oxl <- comCreateObject('Excel.Application')
comSetProperty(oxl, "Visible", TRUE)
owb <- comGetProperty(oxl, "Workbooks")
ob <- comInvoke(owb, "Open", xls)
osheets <- comGetProperty(ob, "Worksheets")
n <- comGetProperty(osheets, "Count")
ithSheetName <- function(i)
	comGetProperty(comGetProperty(osheets, "Item", i), "Name")
sheetNames <- sapply(1:n, ithSheetName)
comInvoke(oxl, "Quit")

library(gdata)
read.xls(xls, match("xyz", sheetNames), na.strings = "na ")
On Thu, Mar 12, 2009 at 10:46 AM, Juergen Rose <rose at rz.uni-potsdam.de> wrote: