简体   繁体   English

当 ID 存储在一个 excel 单元格中时,如何发送多个 email?

[英]How to send multiple email when ids are store in one excel cell?

I have written loop for 1 email id in 1 excel cell but I am unable to write loop when multiple email ids are store in 1 excel cell I have written loop for 1 email id in 1 excel cell but I am unable to write loop when multiple email ids are store in 1 excel cell

Here's a sample这是一个示例

| code   |      email.ids      |        cc            |
|  1     |abc@abc.in;aab@abc.in|as@abc.in;asdb@abc.com|
|  2     |as@abc.in;asdb@abc.in|as@abc.in;asdb@abc.com|

Code Column will be the value for "forloop".代码列将是“forloop”的值。

you can use stringr::str_split(df$email.ids[row], ";") %>% flatten_chr() to extract and split the variable by a given pattern (here: ";"), assuming some consistency.您可以使用stringr::str_split(df$email.ids[row], ";") %>% flatten_chr()按给定模式(此处:“;”)提取和拆分变量,假设有一定的一致性。

The following code will allow to work with each email in a nested loop:以下代码将允许在嵌套循环中使用每个 email:

library(tidyverse)
for (row in 1:nrow(df)) {
    code_i <- df$code[row]
    message("code:", code_i)
    
    vec_email_id <- stringr::str_split(df$email.ids[row], ";") %>% flatten_chr()
    vec_cc <- stringr::str_split(df$email.ids[row], ";") %>% flatten_chr()
    vec_all_mails <- c(vec_email_id, vec_cc)
    
    for (email in vec_all_mails) {
        message("email: ", email)
        # do something with email
    }
}
#> code:1
#> email: abc@abc.in
#> email: aab@abc.in
#> email: abc@abc.in
#> email: aab@abc.in
#> code:2
#> email: as@abc.in
#> email: asdb@abc.in
#> email: as@abc.in
#> email: asdb@abc.in

data数据

df <- read.delim(text = 
" code  |      email.ids      |        cc            
  1     |abc@abc.in;aab@abc.in|as@abc.in;asdb@abc.com
  2     |as@abc.in;asdb@abc.in|as@abc.in;asdb@abc.com
", header=TRUE, sep = "|")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM