1

I am facing the following issue: I created a beautiful flextable from a dataframe in R, which I would like to send via email. I use htmltools_value to get the HTML code of the flextable. Now I am able to embed this as htmlbody in my email which works in a sense that I succesfully send the email. However, the email is losing all the colors and borders with rest of the formatting still as defined in the flextable. Anyone faced similar issues or has an idea what could be the problem?

    require(flextable)
    require(RDCOMClient)

    header_col2 <- c("","","", "", "2nd header", "2nd header","More headers", "More headers", "More headers", "More headers") 
    dfTest <- mtcars[c(1:6),c(1:10)] 
    ft <- flextable(dfTest) 
    ft <- add_header_row(ft,values = header_col2,top = T,colwidths = c(rep(1,10))) ft <- merge_h(ft, part = "header") 
    ft <-bold(ft, bold=T, part="header") 
    ft <-theme_zebra(ft,odd_header = 'red', even_header = 'grey', odd_body   = 'lightblue', even_body = "white") 
    ft <- color(ft, color = "white", part = "header") 
    ft <- bold(ft, bold = TRUE, part = "header") 
    ft <- fontsize(ft, size = 11, part = "header") 
    std_border = fp_border(color="white", width = 1.5) 
    big_border = fp_border(color="gray", width = 1) 
    ft <- border_outer(ft, part="all", border = big_border ) 
    ft <- border_inner_v(ft, part="header", border = std_border ) 
    body <- htmltools_value(ft)
    # or body <- format(ft, type = "html") 
OutApp <- COMCreate("Outlook.Application") 
outMail = OutApp$CreateItem(0) 
outMail[["To"]] = "test@test.com" 
outMail[["subject"]] = "TEST" 
outMail[["HTMLbody"]] = body 
outMail$Send()
SRO
  • 11
  • 2
  • I don't think you can use htmltools_value. You can read read https://stackoverflow.com/a/54844443/3315962. – David Gohel Mar 13 '19 at 15:25
  • Thanks for this. Unfortunately that doesn’t change anything. Still missing the colors and borders in the table within the email body. Also what confuses me is the fact that I can save the html code as a file and open it in a browser with the complete formatting. Just outlook seems to not display the html code similarly. I might need to improve my html game. – SRO Mar 14 '19 at 12:02
  • With no code it's not possible to help You could repost with a reproducible code, so that people could see what packages and codes are used and maybe help you. :) – David Gohel Mar 14 '19 at 13:06

0 Answers0