2016-12-22 7 views
2

RDCOMClinetパッケージでOutlookにExcelファイルを添付できます。 Rでメール本文にExcelワークシートのコンテンツを表示するにはどうすればよいですか? テーブルがあり、ワークシートにグラフが含まれているとします。テーブル部分についてはOutlook本体にExcelワークシートを表示する方法R

library(RDCOMClient) 
## init com api 
OutApp <- COMCreate("Outlook.Application") 
## create an email 
outMail = OutApp$CreateItem(0) 

## configure email parameter 
outMail[["To"]] = "[email protected]" 
outMail[["subject"]] = paste0("Report ", Sys.Date() - 1) 

# attach a file via its directory 
dirs <- dir(getwd(), full.names = TRUE) 
outMail[["Attachments"]]$Add(dirs) 

# insert an excel worksheet from attachment or local drive 
outMail[["HTMLBody"]] = ? 

答えて

2

、あなたは一例

library(RDCOMClient) 
library(openxlsx) 
library(xtable) 

OutApp <- COMCreate("Outlook.Application") 
outMail = OutApp$CreateItem(0) 
outMail[["To"]] = "[email protected]" 
outMail[["subject"]] = paste0("Report ", Sys.Date() - 1) 

wb <- createWorkbook() 
addWorksheet(wb, "S1") 
writeDataTable(wb, "S1", x = head(iris)) 
saveWorkbook(wb, tf <- tempfile(fileext = "xlsx")) 
df <- read.xlsx(tf) 
df_html <- print(xtable(df), type="html", print.results=FALSE) 

outMail[["Attachments"]]$Add(tf) 
outMail[["HTMLBody"]] = sprintf(' 
Hello world, here is the table: 
%s 
Merry Christmas & a happy New Year! 
', df_html) # add your html message content here 
outMail$Send() 

enter image description here

のために何ができる私は、チャートの一部のオプションを知りません。 ExcelのチャートをOutlookの電子メールに埋め込んで、結果のHTMLを調べることができますか?

関連する問題