导出 data.table 并在新行中打印单元格内容
Export data.table and print cells content in new lines
让我们有一个数据框:
df <- data.frame(c('Warsaw; Nairobi'),c('Mogadishu; Ottawa'),c('Berlin; Paris'))
colnames(df)<-c('a','b','c')
现在是时候将数据导出到 table.docx
library(officer)
library(flextable)
library(magrittr)
my_doc <- read_docx()
export <- my_doc%>%body_add_table(df)
print(export, target = "my_path/table.docx")
我想交换分号以强制 MS Word 在同一单元格中以新行打印首都城市。
右栏赞:
将;
替换为\n
:
df$a <- gsub("; ", "\\n", df$a)
df$b <- gsub("; ", "\\n", df$b)
df$c <- gsub("; ", "\\n", df$c)
flextable(df)
让我们有一个数据框:
df <- data.frame(c('Warsaw; Nairobi'),c('Mogadishu; Ottawa'),c('Berlin; Paris'))
colnames(df)<-c('a','b','c')
现在是时候将数据导出到 table.docx
library(officer)
library(flextable)
library(magrittr)
my_doc <- read_docx()
export <- my_doc%>%body_add_table(df)
print(export, target = "my_path/table.docx")
我想交换分号以强制 MS Word 在同一单元格中以新行打印首都城市。
右栏赞:
将;
替换为\n
:
df$a <- gsub("; ", "\\n", df$a)
df$b <- gsub("; ", "\\n", df$b)
df$c <- gsub("; ", "\\n", df$c)
flextable(df)