代码之家  ›  专栏  ›  技术社区  ›  Mark

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

  •  3
  • Mark  · 技术社区  · 8 年前

    使用 officer 在R中打包,使用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\U带\U文本 反复地

    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)
    

    但这最终会将文本覆盖在同一行上,造成无法阅读的混乱。

    如何,via 官员 ,将文本添加到幻灯片,以实现多个项目符号和缩进子元素?

    1 回复  |  直到 8 年前
        1
  •  6
  •   David Gohel    8 年前

    功能 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")