【发布时间】:2019-07-12 21:42:16
【问题描述】:
我正在尝试使用 OfficeR 生成一些 powerpoint 报告,但无法将结果保存到文件中。
我能够处理数据并填充占位符。当我使用slide_summary() 时,会显示用于占位符的内容,但在输出文件中不可见。
我的代码如下所示:
# read template
pptx <- read_pptx("sample_pptx.pptx")
# open slide 5
slide <- on_slide(pptx, 5)
# add text to pre-existing placeholder
ph_add_text(slide, str = "sample_text", ph_label = "sample_ph")
# check content of slide
slide_summary(slide)
# save presentation
print(pptx, target = "outfile.pptx")
输出:
> slide_summary(slide)
type id ph_label offx offy cx cy text
1 body 2 sample_ph NA NA NA NA sample_text
> print(pptx, target = "outfile.pptx")
[1] "C:/Users/mhuber/OfficeR/outfile.pptx"
无论我做什么,文本都不会出现在我的输出文件中。
【问题讨论】:
-
我无法运行代码,因为缺少 sample_pptx.pptx。你能让代码可重现吗?
-
嗨大卫,很高兴收到你这么快的消息! sample_pptx.pptx 只是一个空文件,包含 5 张幻灯片和第 5 张幻灯片的占位符。You can download it here
-
那里可能有错误...我需要更多时间来理解。你不能用 ph_with 代替现有的空幻灯片吗?在您的模板中,您的幻灯片都是空的,ph_add_text 仅用于将文本添加到现有形状/ph 中。
-
这只是一个小例子,不幸的是,我真正的 powerpoint 输入文件在幻灯片 5 之前和之后已经有内容。我可能会尝试使用 move_slide 解决这个问题,但我当然更愿意让我最初的想法发挥作用。
-
当然,我明白了。我将很快改进 doc et 希望有时间解决这个问题。很抱歉给您带来不便