我使用 rmarkdown 创建了以下格式良好的表并保存为 table.rmd 文件。
library(RDCOMClient)
kable(mtcars[1:5, 1:6]) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed"),
full_width = T,
position = "left",
font_size = 13,
fixed_thead = list(enabled = T, background = "#c5d9f1")) %>%
column_spec(1, bold = T, border_right = T) %>%
column_spec(2, width = "5cm", background = "yellow") %>%
row_spec(4:5, bold = T, color = "white", background = "grey")
现在,我想使用以下代码将此文件/表格作为电子邮件正文通过 Outlook 发送,同时保留表格的原始格式。
rmarkdown::render("table.Rmd", "html_document")
OutApp <- COMCreate("Outlook.Application")
outMail = OutApp$CreateItem(0)
outMail[["To"]] = "email@abc.com"
outMail[["subject"]] = paste0("Report ", Sys.Date() - 1)
df_html <- read table.html as html so that the df_html gets correctly displayed as well formatted html table.
outMail[["HTMLBody"]] = df_html
outMail$Send()
我该怎么做?我的信念是,如果我可以在 R 中将 table.html 读取为 html 本身,我就可以做到这一点。那么,如果这是正确的,我如何创建可以分配给 outMail[["HTMLBody"]] 的 df_html 以使其正常工作?