Reputation: 11
I am trying to add a picture to a powerpoint slide, in R using RDCOMClient and running into an error:
updatePicture <- function(Slide, ShapeName, ImageFileName) {
shape <- getShapeByName(Slide, ShapeName)
if (shape$Type() == 13 || shape$Type() == 12) {
filename <- file.path(paste(getwd(), ImageFileName, sep="/"))
if (file.exists(filename)) {
left <- shape$Left()
top <- shape$Top()
width <- shape$Width()
height <- shape$Height()
shapes <- Slide$Shapes()
shape$Delete()
shape <- shapes$AddPicture(filename, FALSE, TRUE, left, top, width, height)
}
shape[["Name"]] <- ShapeName
}
}
Browse[2]> n
debug at C:/Projects/Macys/ProductTests/powerpoint_functions.R#64: shape <- shapes$AddPicture(filename, FALSE, TRUE, left, top, width, height)
Browse[2]> n
<checkErrorInfo> 80020009
No support for InterfaceSupportsErrorInfo
checkErrorInfo -2147352567
Error: Exception occurred
Please help!
Upvotes: 0
Views: 106
Reputation: 2233
It is hard to tell what your error is. It would be helpful if you could provide all you code and an example of a PowerPoint for which you want to add a picture.
You can consider the following approach to add a picture in a PowerPoint with RDCOMClient :
setwd("D:\\")
x <- c(1 : 7)
y <- c(1 : 7)
png("test3.png")
plot(x,y, bg = "transparent")
dev.off()
library(RDCOMClient)
pptapp <- COMCreate("PowerPoint.Application")
pptapp[["Visible"]] <- TRUE
pptpres <- pptapp$Presentations()$Open("D:\\test3.pptx")
pptLayout <- pptapp$ActivePresentation()$Slides(1)$CustomLayout()
pptNewSlide <- pptapp$ActivePresentation()$Slides()$AddSlide(pptapp$ActivePresentation()$Slides()$Count() + 1, pptLayout)
pptNewSlide$Shapes()$AddPicture("D:\\test3.png", TRUE, TRUE, 150, 150)
Upvotes: 0