我正在尝试使用高级程序包自动化我的PowerPoint报告;但是,我无法了解如何定制文本(字体大小、颜色、字体)。
为了添加文本,我使用了ph_with()函数。我试着使用军官的ftext()函数定制它,但是它不起作用。用这个例子
library(officer)
dataframe <- data.frame(column="Sample")
ppt_temp <- read_pptx()
ppt_temp <- add_slide(ppt_temp)
properties <- fp_text(color = "red", font.size = 28, bold = TRUE)
slide_title <- ftext(paste0("These data cover ", dataframe$column[1]), properties)
slide <- ph_with(x = ppt_temp, value = slide_title,
location = ph_location_type(type = "title"))我得到以下错误
Error in UseMethod("ph_with", value) :
no applicable method for "ph_with" applied to an object of class "c('ftext', 'cot', 'run')"如果我不尝试设置文本属性,这将有效
slide <- ph_with(x = ppt_temp, value = paste0("These data cover ", dataframe$column[1]),
location = ph_location_type(type = "title))有什么建议吗?
发布于 2020-08-11 21:04:19
ph_with似乎希望这个值在段落包装器中。将文本对象包装在fpar()中。试一试
slide <- ph_with(x = ppt_temp, value = fpar(slide_title),
location = ph_location_type(type = "title"))因此,一个充分发挥作用的例子是
library(officer)
dataframe <- data.frame(column="Sample")
ppt_temp <- read_pptx()
ppt_temp <- add_slide(ppt_temp)
properties <- fp_text(color = "red", font.size = 28, bold = TRUE)
slide_title <- ftext(paste0("These data cover ", dataframe$column[1]), properties)
slide <- ph_with(x = ppt_temp, value = fpar(slide_title),
location = ph_location_type(type = "title"))
print(ppt_temp, target="temp.pptx")https://stackoverflow.com/questions/63366003
复制相似问题