1

尝试使用官员从 .docx 文档中的数据框中添加表格,但不包括列标题的行。在将数据框添加到文档之前,我尝试从数据框中删除列名,但这没有奏效,并导致 gobbly-gook 被添加到顶行而不是顶行,只是不存在。关于如何做到这一点的任何想法?

NarrativeDoc <- read_docx()
tmp = data.frame(RowHead1=c('Fact 1','Fact 2'),
                 RowHead2=c("I like chicken","I am not a chicken"),
                 stringsAsFactors =FALSE)
names(tmp)=NULL
NarrativeDoc <- body_add_table(NarrativeDoc,tmp)
print(NarrativeDoc,
      target="C:\\Users\\jclark_v\\Documents\\R\\TestNoHeader.docx")
4

1 回答 1

2

我已将参数标头添加到body_add_table(您需要从 github 更新)

NarrativeDoc <- read_docx()
tmp = data.frame(RowHead1=c('Fact 1','Fact 2'),
                 RowHead2=c("I like chicken","I am not a chicken"),
                 stringsAsFactors =FALSE)
NarrativeDoc <- body_add_table(NarrativeDoc,tmp, header = FALSE)
NarrativeDoc <- body_add_par(NarrativeDoc, "")
NarrativeDoc <- body_add_table(NarrativeDoc,tmp, header = TRUE)
print(NarrativeDoc,
      target="TestNoHeader.docx")
于 2017-09-05T16:42:29.473 回答