繁体   English   中英

在 R 中导出 flextable 到 word

[英]Export flextable to word in R

我是R的新手,非常感谢大家的帮助。 我创建了一个 flextable 并想将文件导出到 word 文档。 这很好用。 我按照建议使用了一个临时文件“https://davidgohel.github.io/flextable/reference/save_as_docx.html”。 我尝试将此临时文件导出或保存到我的工作目录,但这不起作用:

 library(officer)
ft1 <- as_flex_table (ex_tbl)
sect_properties <- prop_section(
  page_size = page_size(orient = "landscape",
                        width = 8.3, height = 11.7),
  type = "continuous")
  
save_as_docx(ft1, path = tf)
save_as_docx(`Table 1` = ft1, path = **("\\Users\\XXX\\Desktop\\example_2.docx")**, pr_section = sect_properties).
 save_as_docx(`Table 1` = ft1, path = ("\\Users\\XXX\\Desktop\\example_2.docx"), pr_section = sect_properties)

=> 错误:\Users\XXX\Desktop\example_2.docx 目录不存在。 此外,打印 function 不起作用。

print(tf, target = "c:/Users/Hendrik/Desktop/")

是否可以将临时文件直接保存在工作目录中

尝试使用以下代码:

flextable(your_table) %>% save_as_docx( path = "name.docx")
# The output will be saved to the work space.

例子:

df <- read.table(header=TRUE, text='
 id age
  1     20
  2     27
  3     24
  4     26
  5     20
')

stats <- df  %>% summarise(N = n(),mean = mean(age),
         std=round(sd(age),2),max = max(age),min = min(age))

flextable(stats) %>% save_as_docx( path = "stats.docx")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM