[R] RDCOMClient: how to close Excel process?
J. R. M. Hosking
JRMH001 at gmail.com
Thu Jul 9 15:16:33 CEST 2009
Lauri Nikkinen wrote:
> Thanks again. That did not work either. I get
>
>> library(RDCOMClient)
>> xl <- COMCreate("Excel.Application")
>> wk <- xl$Workbooks()
>> sh <- wk$Open(normalizePath("sample_file.xls"))$Sheets()$Count()
>>
>> wk$Close()
> [1] TRUE
>> xl$Quit()
> NULL
>
> and there is still Excel process open in the Task manager (and
> sample_file.xls won't open).
>
> -L
In my experience, the Excel process will not go away if any
Excel-related object has been created but not destroyed. I suggest that
you explictly remove all Excel objects with rm() and run gc() at the end
to clean up:
library(RDCOMClient)
xl <- COMCreate("Excel.Application")
wk <- xl$Workbooks()
sh<-wk$Open(normalizePath("sample_file.xls"))$Sheets()$Count()
wk$Close()
xl$Quit()
rm(sh)
rm(wk)
rm(xl)
gc()
J. R. M. Hosking
More information about the R-help
mailing list