[R] RDCOMClient: how to close Excel process?

Lauri Nikkinen lauri.nikkinen at iki.fi
Wed Jul 8 15:06:57 CEST 2009


Hi,

I’m using R package RDCOMClient (http://www.omegahat.org/RDCOMClient/)
to retrieve data from MS Excel workbook. I’m using the code below to
count the number of sheets in the workbook and then loop the data from
sheets in to a list.

############# R code ###################
library(gdata)
library(RDCOMClient)

xl <- COMCreate("Excel.Application")
sh <- xl$Workbooks()$Open(normalizePath("sample_file.xls"))$Sheets()$Count()

DF.list <- list()
for (i in 1:sh) {
   DF.list[[i]] <- read.xls("sample_file.xls", sheet=i,
stringsAsFactors = FALSE)
   }
######################################

COMCreate opens Excel process and it can be seen from Windows Task
Manager. When I try to open sample_file.xls in Excel, it just flashes
in the screen and shuts down. When I kill (via task manager) the Excel
process COMCreate started, sample_file.xls will open normally.

The question is, how can I close the Excel process COMCreate started.
xl$Close() doesn’t seem to work. The same problem have been presented
in this post to R-help:
http://tolstoy.newcastle.edu.au/R/help/06/04/25990.html

-L




More information about the R-help mailing list