导出ppt的flextable行中未显示图像

问题描述

我正在尝试导出一张柔性表,使其上面带有图片行,但不显示生成的PowerPoint上,以将其导出到Powerpoint。

不过,它在R studio Viewer上效果很好。

您是否知道问题出在哪里?

预先感谢

    library(kableExtra)
    library(flextable)
    library(officer)
    
    doc <- read_pptx()
    
    img.file <- file.path( R.home("doc"),"html","logo.jpg" )
    
    myft <- flextable( head(mtcars),col_keys = c("am","separator","gear","mpg","drat","qsec" ))
    
    myft <- compose( myft,i = ~ qsec > 18,j = "qsec",value = as_paragraph(as_image( src = img.file,width = .20,height = .15))
    )
    myft <- autofit(myft)
    myft
    
    doc <- add_slide(doc)
    
    doc <- ph_with(doc,value = myft,location = ph_location_template(top = 2,width = 4,type = "body"))
    
    print(doc,target = "./cars.pptx")
    system2('cmd',args = c('/c','"./cars.pptx"'))

解决方法

PowerPoint无法做到这一点,您可以在此处阅读文档:https://davidgohel.github.io/flextable/articles/display.html#limitation-for-powerpoint-1

当输出格式为PowerPoint时,不支持在flextable中使用图像。这不是选择,也不是未实现的功能。这是因为PowerPoint无法将图像嵌入表格单元格中。这是PowerPoint的限制。