【问题标题】:OfficeR: How to add text in word document template on a placeholderOfficeR:如何在占位符上的 Word 文档模板中添加文本
【发布时间】:2021-07-16 06:20:56
【问题描述】:

我想从预先保存的 word 模板生成 word 文档,我在 word 模板上添加了占位符,但我无法将文本保存在占位符位置。我尝试使用 ph_with 函数,但它给出了 .pptx 的错误,请告诉我使用哪个函数将所需的文本保存到特定的占位符位置。另外我通过键入(Placeholder1 ...等)在word模板中添加占位符这是正确的方法吗?

template <- system.file(package = "officer", "doc_examples", "protocol_template.docx")                            
    doc <- read_docx(path = template)
    ph_with(doc, 
            value = input$text, 
            location = ph_location_label(ph_label = "Placeholder1"))

【问题讨论】:

    标签: r officer rshiny


    【解决方案1】:

    加载 word 文档后,您可以使用 body_replace_all_text 函数将所需的文本通过管道输入到文档中。

    body_replace_all_text(
      x,
      old_value,
      new_value,
      only_at_cursor = FALSE,
      warn = TRUE,
      ...
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-08
      • 2010-09-15
      • 1970-01-01
      • 2016-09-23
      • 2020-10-25
      • 2018-11-27
      相关资源
      最近更新 更多