【问题标题】:Dynamic header/footer in R-Markdown knit to word?R-Markdown 中的动态页眉/页脚编织到单词?
【发布时间】:2021-10-11 14:13:36
【问题描述】:

我正在使用 RMarkdown 脚本生成大量报告。我想使用参数向 word-document 输出添加自定义页眉/页脚,例如客户名称。当我从单独的脚本渲染 RMarkdown 时,它会遍历客户端列表并更改数据。我也希望标题更新。

我已经尝试了this question 的答案,但没有成功,并且使用了一个单词参考文档来设置标题。但是使用参考文档,我只能设置一个在参数更改时不更新的静态标题。

标题应该显示:

史蒂夫
2021 年 8 月 6 日
第 X 页,共 3 页

“史蒂夫”在循环时更新为不同的名称。
这是我的 YAML 中的内容:

---
title: "test doc"
author: 
- Author 1
- Author 2
date: "`r format(Sys.time(), '%B %d, %Y')`"
output: 
  word_document:
    reference_docx: test1.docx
params: 
  client: "Steve"
header-includes:
   - \usepackage{fancyhdr}
   - \usepackage{lipsum}
   - \pagestyle{fancy}
   - \fancyhead[LE,L0]{"params$client <br> `r format(Sys.time(), '%B %d, %Y')` <br> Page \thepage of 3"}
  
always_allow_html: true
---

【问题讨论】:

    标签: r ms-word r-markdown knitr


    【解决方案1】:

    使用名称为 ClientName自定义文档属性。 在文档的标题中,有一个字段{ DocProperty ClientName}。 使用您的代码更改文档属性。 请参阅 Word MVP Astrid Zeeland 的 How to use a single VBA procedure to read or write both custom and built-in Document Properties

    【讨论】:

    • 您能告诉我如何调用/更新 r-script 中的自定义文档属性吗?
    • 对不起。我知道 Word 和一些 vba,但不知道 r-script。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    相关资源
    最近更新 更多