我一直在使用office套件来创建幻灯片,但此时,我想将它们全部合并成一个幻灯片集,但无法找出方法。请问是否有任何软件包可以帮助将多个PowerPoint幻灯片集合并成一个?
我一直在使用office套件来创建幻灯片,但此时,我想将它们全部合并成一个幻灯片集,但无法找出方法。请问是否有任何软件包可以帮助将多个PowerPoint幻灯片集合并成一个?
read_pptx()
来读取 deck1 和 deck2 文件。然后,循环遍历 deck2 的幻灯片索引,并使用这些值将其添加到 deck1 中。我认为 officer 中有一个名为 pptx_summary()
的函数,它可以将 pptx R 对象转换为 tibble,但我不确定是否可以将 tibble 转换回 pptx R 对象。pdftools
将它们合并。通过R自动创建PowerPoint幻灯片时(例如使用R markdown的PowerPoint导出),可能需要将它们与预先制作的固定幻灯片(例如带有详细视觉解释)合并。由于目前似乎没有单行解决方案,因此这里提供了一个不完整的答案来回答一个三年前的问题。
查看OfficeR
的源代码可以发现,该软件包使用后台数据结构和临时文件夹,其中包含压缩在XLSX文件中的XML文件。
因此,复制幻灯片需要两个步骤:更新结构和复制XML文件和其他资源。以下是基于OfficeR
类的合并两个PowerPoint文件的非常粗略的草稿。
merge_pptx = function(a, b, filename) {
# go through the slides of b
for (index in 1:length(source$slide$get_metadata())) {
# We need a new filename in the target's slide directory
new_slidename <- target$slide$get_new_slidename()
xml_file <- file.path(target$package_dir, "ppt/slides", new_slidename)
# Copy XML from source to new filename
orgFilename = source$slide$get_metadata()[index, "filename"]
newFilepath = paste(target$package_dir, newFilename, sep="/")
file.copy(orgFilename, xml_file)
# Not sure yet, what exactly this does
slide_info <- target$slideLayouts$get_metadata()[1,] # Use first best layout at the moment
layout_obj <- target$slideLayouts$collection_get(slide_info$filename)
layout_obj$write_template(xml_file)
# update presentation elements
target$presentation$add_slide(target = file.path("slides", new_slidename))
target$content_type$add_slide(partname = file.path("/ppt/slides", new_slidename))
# Add the slide to the collection
target$slide$add_slide(xml_file, target$slideLayouts$get_xfrm_data())
target$cursor <- target$slide$length()
}
print(target, target=filename)
}
source = read_pptx("One.pptx")
target = read_pptx("Two.pptx")
merge_pptx(source, target, "Combined.pptx")
dir_slide
类中的add_slide()
函数,请参见https://github.com/davidgohel/officer/blob/master/R/ppt_class_dir_collection.R。