1

我是使用 Rmarkdown 和官员/officedown 的新手,所以也许有一个简单的解决方法,但我不知所措。我正在尝试使用 officedown/officer 为报告创建 Word 文档,以便我可以更好地控制文本的外观等。我用自己的代码不断得到奇怪的结果,所以基本上只是从https://ardata-fr.github.io/officeverse/formatting-properties.html复制/粘贴一个非常简单的示例(第 7.1 节中的示例)。下面是我输入到 Rmarkdown 中的代码(在需要的地方添加了适当的 --- 和 ``` {r})。再往下是我收到的结果减去我不关心的典型警告。”

title: "Untitled"
author: "author"
date: "7/21/2021"
output: officedown::rdocx_document
knitr::opts_chunk$set(echo = TRUE)
library("officedown")
library("officer")
library("dplyr")
properties1 <- fp_text(color = "#006699", bold = TRUE, font.size = 50)
properties2 <- fp_text(color = "#C32900", bold = TRUE, font.size = 50)
ftext1 <- ftext("hello ", properties1)
ftext2 <- ftext("World", properties2)
paragraph <- fpar(ftext1, ftext2)

read_docx() %>% 
  body_add_fpar(paragraph) %>% print()

以下是我在 word 文档中收到的输出,而不是示例中格式正确的文本。这与我使用自己的代码时得到的非常相似。

知道如何使它看起来正确吗?谢谢!

## rdocx document with 2 element(s)
## 
## * styles:
##                 Normal              heading 1              heading 2 
##            "paragraph"            "paragraph"            "paragraph" 
##              heading 3 Default Paragraph Font           Normal Table 
##            "paragraph"            "character"                "table" 
##                No List                 strong               centered 
##            "numbering"            "character"            "paragraph" 
##         table_template    Light List Accent 2            Titre 1 Car 
##                "table"                "table"            "character" 
##            Titre 2 Car            Titre 3 Car          Image Caption 
##            "character"            "character"            "paragraph" 
##          Table Caption     Table Professional                  toc 1 
##            "paragraph"                "table"            "paragraph" 
##                  toc 2           Balloon Text    Texte de bulles Car 
##            "paragraph"            "paragraph"            "character" 
##           reference_id          graphic title            table title 
##            "character"            "paragraph"            "paragraph" 
## 
## * Content at cursor location:
##   level num_id        text style_name content_type
## 1    NA     NA hello World         NA    paragraph
4

0 回答 0