简体   繁体   English

通过官员向PowerPoint幻灯片添加多个文本符号

[英]Add multiple bullets of text to PowerPoint slide via officer

Using the officer package in R, when working with a PowerPoint you can add text with the function ph_with_text . 使用R中的officer包,在使用PowerPoint时,可以使用ph_with_text函数添加文本。 However, it's not clear how to add multiple bullets of text or how to set the level of indentation. 但是,尚不清楚如何添加多个文本项目符号或如何设置缩进级别。 I would like to achieve the following structure: 我想实现以下结构:

  • Question 1 问题1
    • Answer 1 答案1
    • Answer 2 答案2
  • Question 2 问题2
    • Answer 1 答案1
    • Answer 2 答案2

I have tried two methods which both produce very wrong results. 我尝试了两种方法都会产生非常错误的结果。 I have tried taking my text and adding \\n and \\n\\t to create linebreaks and tabs (like how I would create the structure in PowerPoint. 我已经尝试过输入文本并添加\\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)

This creates the bullets, but not the depth. 这会产生子弹,但不会产生深度。 There's a whitespace tab after each bullet before each answer. 每个答案前面的每个项目符号后面都有一个空格标签。 Additionally, these are not new bullets, if I manually edit the file and press tab on one bullet point, every point after is also shifted. 此外,这些不是新项目符号,如果我手动编辑文件并在一个项目符号点上按Tab,则之后的每个点也会移动。 Clearly the correct structure hasn't been acheived. 显然,尚未实现正确的结构。

I have also tried just calling ph_with_text repeatedly. 我也尝试过仅反复调用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)

But this ends up overlaying the text on the same line and it's an unreadable mess. 但这最终将文本覆盖在同一行上,这是一个难以理解的混乱。

How do I, via officer , add text to a slide achieving multiple bullets and indented sub-elements? 我如何通过officer将文本添加到幻灯片中以实现多个项目符号和缩进的子元素?

The function ph_with_ul is the function you need 函数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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM