【发布时间】:2021-12-10 10:44:37
【问题描述】:
我一直在尝试将 .csv 文件导入 R,然后将其转换为 flextable,然后将 flextable 导出为 Word .docx 文档。我使用以下代码
library(tidyverse)
library(readxl)
library(scales)
library(janitor)
library(stringr)
library(magrittr)
library(officer)
library(flextable)
library(dplyr)
# load data ---------------------------------------------------------------
Rpops_survey <- read_csv("R-POPS Data Quant.csv")
spec(Rpops_survey)
# convert data ------------------------------------------------------------
Rpops_survey_dframed <- as.data.frame(Rpops_survey)
Rpops_ft1 <- flextable(Rpops_survey_dframed)
Rpops_doctemp <- read_docx()
Rpops_doctemp <- body_add_flextable(Rpops_doctemp, value = Rpops_ft1)
# export data -------------------------------------------------------------
fileout <- tempfile(fileext = ".docx")
fileout <- "test.docx"
print(Rpops_doctemp, target = fileout)
【问题讨论】: