【问题标题】:Add multiple bullets of text to PowerPoint slide via officer通过官员将多个文本项目符号添加到 PowerPoint 幻灯片
【发布时间】:2018-05-16 15:44:36
【问题描述】:

使用 R 中的 officer 包,在使用 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向幻灯片添加文本以实现多个项目符号和缩进子元素?

【问题讨论】:

    标签: r officer


    【解决方案1】:

    函数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")
    

    【讨论】:

      猜你喜欢
      • 2021-01-21
      • 2015-07-26
      • 2022-01-24
      • 1970-01-01
      • 2022-09-26
      • 2018-11-01
      • 2015-07-27
      • 1970-01-01
      • 2020-09-22
      相关资源
      最近更新 更多