首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用RDCOMClient将图形粘贴到Powerpoint中

使用RDCOMClient将图形粘贴到Powerpoint中
EN

Stack Overflow用户
提问于 2016-06-15 18:16:36
回答 1查看 424关注 0票数 1

我使用代码将图表保存到剪贴板上。

代码语言:javascript
复制
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")

使用RDCOMClient,我想将这个图表添加到我打开的Powerpoint演示文稿中。

代码语言:javascript
复制
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]]

我知道我可以使用PP = PPT.AddGraphicstoSlide(PP),但这不允许进行相同的定制。也就是说,它没有从我的情节中传递出"bg =‘透明’“的效果,而是形成了一个白色的方形面包房,覆盖了我在背景中所写的文字。我可以很容易地手动修复这个问题,但是我正在将数百个图形生成到多个演示文稿中,并且希望它能够被自动化。是否有方法将保存到wmf格式剪贴板上的图形粘贴到正确幻灯片的powerpoint演示文稿中?谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2022-10-01 18:02:34

我已经能够用下面的代码在PowerPoint和RDCOMClient中添加一张图片:

代码语言:javascript
复制
###########################
#### 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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37842891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档