Officer - 用制表符粘贴文本
Officer - paste text with tabulator
我正在尝试在字符串“名称:”和 iris 数据库中的实际物种名称之间集成 2 个制表符。我想要 word.docx 中的格式化文本。
有人可以帮助我吗?
my_prop_1 = officer::fp_text(font.size = 10, underlined=T, bold = TRUE, font.family = "Arial")
my_prop_2 = officer::fp_text(font.size = 11, underlined=T, bold = TRUE, font.family = "Arial")
my_prop_3 = officer::fp_text(font.size = 11, underlined=F, bold = TRUE, font.family = "Arial")
my_prop_4 = officer::fp_text(font.size = 10, underlined=F, bold = T, font.family = "Arial")
my_prop_5 = officer::fp_text(font.size = 10, underlined=T, bold = F, font.family = "Arial")
my_prop_6 = officer::fp_text(font.size = 10, underlined=F, bold = F, font.family = "Arial")
lapply(1:10, function(x) {
empty_docs <- officer::read_docx()
sample_doc <- empty_docs %>% officer::body_add_fpar(officer::fpar(officer::ftext(paste("Name:"),
my_prop_5),
officer::ftext(paste(iris$Species)[[x]], my_prop_6)))
print(sample_doc, target = paste0("Test",x,".docx"))
if (any(list.files() == paste0("Test",x,".docx")))
{cat(paste("File is saved. \n"))}
#return(sample_doc)
})
谢谢,
纳丁
您可以使用 \t
作为制表符。
library(officer)
library(magrittr)
read_docx() %>%
body_add_fpar(fpar("Name:\t\tdoudou bleu"), style = "Normal") %>%
print(target = "test.docx")
我正在尝试在字符串“名称:”和 iris 数据库中的实际物种名称之间集成 2 个制表符。我想要 word.docx 中的格式化文本。 有人可以帮助我吗?
my_prop_1 = officer::fp_text(font.size = 10, underlined=T, bold = TRUE, font.family = "Arial")
my_prop_2 = officer::fp_text(font.size = 11, underlined=T, bold = TRUE, font.family = "Arial")
my_prop_3 = officer::fp_text(font.size = 11, underlined=F, bold = TRUE, font.family = "Arial")
my_prop_4 = officer::fp_text(font.size = 10, underlined=F, bold = T, font.family = "Arial")
my_prop_5 = officer::fp_text(font.size = 10, underlined=T, bold = F, font.family = "Arial")
my_prop_6 = officer::fp_text(font.size = 10, underlined=F, bold = F, font.family = "Arial")
lapply(1:10, function(x) {
empty_docs <- officer::read_docx()
sample_doc <- empty_docs %>% officer::body_add_fpar(officer::fpar(officer::ftext(paste("Name:"),
my_prop_5),
officer::ftext(paste(iris$Species)[[x]], my_prop_6)))
print(sample_doc, target = paste0("Test",x,".docx"))
if (any(list.files() == paste0("Test",x,".docx")))
{cat(paste("File is saved. \n"))}
#return(sample_doc)
})
谢谢, 纳丁
您可以使用 \t
作为制表符。
library(officer)
library(magrittr)
read_docx() %>%
body_add_fpar(fpar("Name:\t\tdoudou bleu"), style = "Normal") %>%
print(target = "test.docx")