1

I have saved a graph to my cliboard using the code

x = c(1:5)
y = c(1:5)
windows(504, 360) #opens a separate window with the size you want 
plot.new()
plot(x,y, bg = "transparent")#my graph has more information but this would work
savePlot("clipboard", type="wmf")

using RDCOMClient, I would like to add this graph to my Powerpoint Presentation that I have open.

PP = PPT.Init(visible = FALSE, method = "RDCOMClient")
PP = PPT.AddTitleSlide(PP, title = "test")
PP = PPT. AddTextSlide(PP, text = "This text will be covered if the graph is in the wrong place")

presentation = PP$pres
slide2 = presentation[["Slides"]][[2]]

I know I can use PP = PPT.AddGraphicstoSlide(PP) but this does not allow for the same customization. Namely it does not carry over the "bg = 'Transparent'" effect from my plot; it instead makes a white square bakground that covers the text I am writing in the background. I can easily fix this manually but I am generating hundreds of graphs into multiple presentations and would prefer it to be automated. Is there a way to paste my graph that is saved to the clipboard in wmf format into my powerpoint presentation at the correct slide? Thanks for the help

W Anderson
  • 53
  • 1
  • 5

1 Answers1

0

I have been able to add a picture in a PowerPoint with RDCOMClient with the following code :

###########################
#### Generate an image ####
###########################
setwd("D:\\")
x <- c(1 : 5)
y <- c(1 : 5)
png("test.png")
plot(x,y, bg = "transparent")
dev.off()

######################################
#### Load the image in PowerPoint ####
######################################
library(RDCOMClient)
pptapp <- COMCreate("PowerPoint.Application") 
pptapp[["Visible"]] <- TRUE
pptpres <- pptapp$Presentations()$Open("D:\\test1.pptx")
pptLayout <- pptapp$ActivePresentation()$Slides(1)$CustomLayout()
pptNewSlide <- pptapp$ActivePresentation()$Slides()$AddSlide(pptapp$ActivePresentation()$Slides()$Count() + 1, pptLayout)
pptNewSlide$Shapes()$AddPicture("D:\\test.png", TRUE, TRUE, 100, 100)
Emmanuel Hamel
  • 1,769
  • 7
  • 19