[R] Creating Excel-Charts via RDCOMClient

Dr. Michael Wolf m-wolf at muenster.de
Sat Jun 27 13:06:59 CEST 2009


Hi R-users!

I'm trying to create an easy Excel chart using the package RDCOMClient. The
following example is working fine:

#-------------------------------------------------------------------
library(RDCOMClient)

xlLocationAsObject <-2
xlXYScatterSmoothNoMarkers <- 73

ex <- COMCreate("Excel.Application")
wb <- ex[["Workbooks"]]$Add()
sh <- ex$ActiveSheet()
ex[["Visible"]] <- TRUE

r <- sh$Range("A1:D1")
r[["Value"]] <- c(1:4)

ch <- ex$Charts()
ch$Add()
ac <- ex$ActiveChart()
ac[["ChartType"]] <- xlXYScatterSmoothNoMarkers
ac$Location(Where=xlLocationAsObject, Name="Tabelle1")
ac$SeriesCollection()$NewSeries()
ac$SeriesCollection(1)[["XValues"]] <- r
ac$SeriesCollection(1)[["Values"]] <- r
#-------------------------------------------------------------------

But I don't perfer this way writing calculated values like "c(1:4)" to the
Excel Sheet and calling them via "SeriesCollection". I'm looking for direct
adressing to "SeriesCollection". But codes like

ac$SeriesCollection(1)[["XValues"]] <- asCOMArray(c(1:4))
ac$SeriesCollection(1)[["Values"]]  <- asCOMArray(c(1:4))

were not successfull. E.g. the code above produces the error message "OLE
error 0x800a01a8".

Ok, I know that there are better ways to solve my problem by using the
RExcel/statconn tools. Unfortunately the conditions under which I work
(partly using other computers by adressing R on my working computer) permit
the use of these tools. As I see, my best chance is a solution with
RDCOMClient. (A clipboard solution which I developed some month ago are very
slow when using large data matrices.)

So, could anyone help me solving the problem?

Thanks,

Michael Wolf
Von-Schonebeck-Ring 18
D-48161 Muenster




More information about the R-help mailing list