2

使用officerR 中的包,在使用 PowerPoint 时,您可以使用函数添加文本ph_with_text。但是,尚不清楚如何添加多个文本项目符号或如何设置缩进级别。我想实现以下结构:

  • 问题 1
    • 答案 1
    • 答案 2
  • 问题2
    • 答案 1
    • 答案 2

我尝试了两种方法,它们都产生了非常错误的结果。我尝试获取文本并添加\n\n\t创建换行符和制表符(就像我将如何在 PowerPoint 中创建结构一样。

doc = read_pptx()
doc = add_slide(layout = "Title and Content", master = "Office Theme")
doc = ph_with_text(doc,type = "body", 
      str = "Question 1\n\tAnswer 1\n\tAnswer 2\nQuestion 2\n\tAnswer 1\n\tAnswer 2", 
      index = 1)

这会创建子弹,但不会创建深度。每个答案之前的每个项目符号后面都有一个空格选项卡。此外,这些不是新项目符号,如果我手动编辑文件并在一个项目符号点上按 Tab,则之后的每个点也会移动。显然,正确的结构还没有实现。

我也试过ph_with_text反复打电话。

doc = add_slide(layout = "Title and Content", master = "Office Theme")
doc = ph_with_text(doc,type = "body", str = "Question 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 2", index = 1)
doc = ph_with_text(doc,type = "body", str = "Question 2", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 1", index = 1)
doc = ph_with_text(doc,type = "body", str = "Answer 2", index = 1)

但这最终会覆盖同一行上的文本,这是一个难以理解的混乱。

如何通过officer向幻灯片添加文本以实现多个项目符号和缩进子元素?

4

1 回答 1

6

功能ph_with_ul就是你需要的功能

library(magrittr)
pptx <- read_pptx()
pptx <- add_slide(x = pptx, layout = "Title and Content", master = "Office Theme")
pptx <- ph_with_text(x = pptx, type = "title", str = "Example title")
pptx <- ph_with_ul(
  x = pptx, type = "body", index = 1,
  str_list = c("Level1", "Level2", "Level2", "Level3", "Level3", "Level1"),
  level_list = c(1, 2, 2, 3, 3, 1),
  style = fp_text(color = "red", font.size = 0) )
print(pptx, target = "example2.pptx")
于 2018-05-16T07:44:36.490 回答