使用 R 中的 officer 包删除演示文稿的幻灯片
Removing slides of a presentation using officer package in R
我正在使用 R 中的 officer 包将我的绘图作为输出传输到 powerpoint 演示文稿。
每次我 运行 代码时,我都想确保 pptx 中没有我想保存图表的幻灯片。
现在我知道如何从演示文稿中删除单张幻灯片了。但我不知道如何一次删除所有幻灯片。
到目前为止我的代码是:
library(officer)
# reading template slides and adding slide in which I want my plot
doc <- read_pptx("U://30-Power & Water//25 Renewables//WORK//Config//Templates//Template.pptx")
doc <- add_slide(doc, layout = "Title and Content",master = "Office Theme")
doc <- ph_with_gg(doc, value = Sweihan ) #plot = ggplot
# Reading the output slides and removing slides (it is just removing one slide so far)
output <- read_pptx("U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx")
output <- remove_slide(output)
print(output, target = "U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx" ) %>% invisible()
# tranfering results to output ppt file
print(doc, target = "U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx" ) %>% invisible()
我可以在使用 officer 包的代码中使用什么功能来一次删除所有幻灯片?
我们将不胜感激!
此致
remove_slide
中 index
参数的文档是
Usage:
remove_slide(x, index = NULL)
index - slide index, default to current slide position
因此,您可以按如下方式一次删除一张幻灯片:
for (n in rev(seq_len(length(output)))) {
remove_slide(output, n)
}
#show number of slides
length(output)
我正在使用 R 中的 officer 包将我的绘图作为输出传输到 powerpoint 演示文稿。
每次我 运行 代码时,我都想确保 pptx 中没有我想保存图表的幻灯片。
现在我知道如何从演示文稿中删除单张幻灯片了。但我不知道如何一次删除所有幻灯片。
到目前为止我的代码是:
library(officer)
# reading template slides and adding slide in which I want my plot
doc <- read_pptx("U://30-Power & Water//25 Renewables//WORK//Config//Templates//Template.pptx")
doc <- add_slide(doc, layout = "Title and Content",master = "Office Theme")
doc <- ph_with_gg(doc, value = Sweihan ) #plot = ggplot
# Reading the output slides and removing slides (it is just removing one slide so far)
output <- read_pptx("U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx")
output <- remove_slide(output)
print(output, target = "U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx" ) %>% invisible()
# tranfering results to output ppt file
print(doc, target = "U://30-Power & Water//25 Renewables//WORK//Result//Result.pptx" ) %>% invisible()
我可以在使用 officer 包的代码中使用什么功能来一次删除所有幻灯片?
我们将不胜感激!
此致
remove_slide
中 index
参数的文档是
Usage: remove_slide(x, index = NULL)
index - slide index, default to current slide position
因此,您可以按如下方式一次删除一张幻灯片:
for (n in rev(seq_len(length(output)))) {
remove_slide(output, n)
}
#show number of slides
length(output)