将flextable导出为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的目录不存在。此外,打印功能不起作用。

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")

最新更新