【问题标题】:Officer - paste text with tabulator官员 - 使用制表符粘贴文本
【发布时间】:2022-04-28 18:17:40
【问题描述】:

我正在尝试在字符串“名称:”和 iris 数据库中的实际物种名称之间集成 2 个制表符。我想在 word.docx 中有一个格式化的文本。 有人能帮我吗?

my_prop_1 = officer::fp_text(font.size = 10, underlined=T, bold = TRUE, font.family = "Arial")
my_prop_2 = officer::fp_text(font.size = 11, underlined=T, bold = TRUE, font.family = "Arial")
my_prop_3 = officer::fp_text(font.size = 11, underlined=F, bold = TRUE, font.family = "Arial")
my_prop_4 = officer::fp_text(font.size = 10, underlined=F, bold = T, font.family = "Arial")
my_prop_5 = officer::fp_text(font.size = 10, underlined=T, bold = F, font.family = "Arial")
my_prop_6 = officer::fp_text(font.size = 10, underlined=F, bold = F, font.family = "Arial")

lapply(1:10, function(x) {
  empty_docs <- officer::read_docx()

  sample_doc <- empty_docs %>% officer::body_add_fpar(officer::fpar(officer::ftext(paste("Name:"), 
                                                                                   my_prop_5),
                                                                    officer::ftext(paste(iris$Species)[[x]], my_prop_6)))
  print(sample_doc, target = paste0("Test",x,".docx"))
  if (any(list.files() == paste0("Test",x,".docx"))) 
  {cat(paste("File is saved. \n"))}
  #return(sample_doc)
}) 

谢谢, 纳丁

【问题讨论】:

    标签: r officer formatted-text


    【解决方案1】:

    您可以使用 作为制表符。

    library(officer)
    library(magrittr)
    
    read_docx() %>% 
      body_add_fpar(fpar("Name:		doudou bleu"), style = "Normal") %>% 
      print(target = "test.docx")
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多