在R中将图像添加到ppt模板
add images to ppt template in R
我想将图像添加到我有 34 张幻灯片的 PowerPoint 模板中,其中所有幻灯片都只有标题和页码。我正在使用 officer
库。我只想在标题下的所需幻灯片上添加图像。
在代码中,我试图将图像添加到第 5 张幻灯片,其中显示错误:幻灯片 $get_xfrm(type = type, index = index) 错误:
类型 body 在幻灯片版式
中不可用
my_pres <- read_pptx("myppt.pptx")
my_pres <- my_pres %>% on_slide(index = 5) %>%
ph_with_img(type="body", index=3, src="imges/1.png", height=1.06, width=1.39)
您想告诉我们您的代码给出了什么错误(如果有)吗?
告诉我们您在 'my_pres' 变量中有什么?您是否阅读了模板文件 (read_pptx()
),是否加载了幻灯片(我知道您有 on_slide()
但您没有将其传送到下一行代码)。
你需要稍微详细一点。
编辑:
根据您的补充意见:
您的幻灯片 (5) 很可能是没有 body 部分的空白幻灯片。这就是错误显示 "type body is not available" 的原因。
尝试删除第 5 张幻灯片并使用此代码:
my_pres <- my_pres %>%
add_slide(layout="Title and Content", master = "Office Theme") %>%
on_slide(index = 6) %>%
ph_with_img(type="body", index=1, src="imges/1.png", height=1.06, width=1.39)
2a。如您所见,创建新幻灯片并指定 'Title and Content' 布局可确保有一个 'body' 可将您的图像添加到其中。为我工作
- 或者,确保您的 'slide 5' 有标题和内容部分。内容部分用作 body.
我想将图像添加到我有 34 张幻灯片的 PowerPoint 模板中,其中所有幻灯片都只有标题和页码。我正在使用 officer
库。我只想在标题下的所需幻灯片上添加图像。
在代码中,我试图将图像添加到第 5 张幻灯片,其中显示错误:幻灯片 $get_xfrm(type = type, index = index) 错误: 类型 body 在幻灯片版式
中不可用my_pres <- read_pptx("myppt.pptx")
my_pres <- my_pres %>% on_slide(index = 5) %>%
ph_with_img(type="body", index=3, src="imges/1.png", height=1.06, width=1.39)
您想告诉我们您的代码给出了什么错误(如果有)吗?
告诉我们您在 'my_pres' 变量中有什么?您是否阅读了模板文件 (read_pptx()
),是否加载了幻灯片(我知道您有 on_slide()
但您没有将其传送到下一行代码)。
你需要稍微详细一点。
编辑:
根据您的补充意见:
您的幻灯片 (5) 很可能是没有 body 部分的空白幻灯片。这就是错误显示 "type body is not available" 的原因。
尝试删除第 5 张幻灯片并使用此代码:
my_pres <- my_pres %>% add_slide(layout="Title and Content", master = "Office Theme") %>% on_slide(index = 6) %>% ph_with_img(type="body", index=1, src="imges/1.png", height=1.06, width=1.39)
2a。如您所见,创建新幻灯片并指定 'Title and Content' 布局可确保有一个 'body' 可将您的图像添加到其中。为我工作
- 或者,确保您的 'slide 5' 有标题和内容部分。内容部分用作 body.