如何解决如何使用 Office 以编程方式向 Power Point 幻灯片添加内容?
我正在使用 Office 和以编程方式创建的表格创建 Power Point 演示文稿。数据一直在变化,所以我的目标是使用 for 循环或其他方法。
在下面的示例中,我将 3 个 flextable
对象存储在列表中。在我的实际问题中,这些将是更多的表(通常> 30 个表)。我还需要每张幻灯片包含一张表格。
然后,我创建一张幻灯片并使用 for 循环将每个表格添加到幻灯片中。但是此时我收到错误:
Error in UseMethod("ph_with",value) :
no applicable method for 'ph_with' applied to an object of class "list"
当从列表中选择或取消列出项目时,对象类不再是 flextable
并且函数 ph_with()
不喜欢那样。我也试过使用 unlist
但得到同样的错误。
有没有办法以编程方式运行 ph_with()
,为每张幻灯片添加 1 个项目(表格和/或图表)?
谢谢
library(magrittr)
library(officer)
library(flextable)
# Areate tables (in my code these are create programmatically using a for loop)
ft1 <- qflextable(head(airquality))
ft2 <- qflextable(head(ggplot2::diamonds))
ft3 <- qflextable(head(mtcars))
# Atore flextables in a list
table_list <- list(ft1,ft2,ft3)
# Create slide
my_pres <- read_pptx()
# Add 1 table per slide from the list created prevIoUsly
for(i in 1:length(table_list)) {
my_pres <- my_pres %>%
add_slide(my_pres,layout = "Title and Content",master = "Office Theme") %>%
ph_with(table_list[i],location = ph_location_type(type = "body"))
}
# I get an error here!!!
# Error in UseMethod("ph_with",value) :
# no applicable method for 'ph_with' applied to an object of class "list"
print(my_pres,target = "My_presentation.pptx")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。