【问题标题】:Get a comma separated cell value list using gspread使用 gspread 获取逗号分隔的单元格值列表
【发布时间】:2015-10-01 13:16:47
【问题描述】:

我想使用 Google 电子表格中存储的电子邮件地址发送邮件。我能够获得单元格值,但我得到了:

(<Cell R1C1 'email@gmail.com'>,)
(<Cell R2C1 'email1@gmail.com'>,)
...

为了使用 MIMEMultipart,我需要一个逗号分隔: email@gmail.com,email1gmail.com,...

这是我的代码:

import gspread
import json
from oauth2client.client import SignedJwtAssertionCredentials
import gdata.spreadsheet.service
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smtplib

json_key = json.load(open('xxx.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)

wks = gc.open('xxx')
worksheet_id = 'od6'
worksheet = wks.get_worksheet(0)

print worksheet.row_values("A1")

for x in xrange(1,50):
test = "A%s" %x
msg = MIMEMultipart()
msg["To"] = worksheet.acell(test),
print msg["To"]

【问题讨论】:

    标签: python python-2.7 mime gspread


    【解决方案1】:

    如果有人想要我找到的解决方案:

    import gspread
    import json
    from oauth2client.client import SignedJwtAssertionCredentials
    import gdata.spreadsheet.service
    from email.MIMEMultipart import MIMEMultipart
    from email.MIMEText import MIMEText
    import smtplib
    
    json_key = json.load(open('AUTH2.json'))
    scope = ['https://spreadsheets.google.com/feeds']
    credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
    gc = gspread.authorize(credentials)
    
    wks = gc.open('Name-of-your-spreadsheet')
    worksheet_id = 'od6'
    worksheet = wks.get_worksheet(0)
    server = smtplib.SMTP('smtp.gmail.com:25')
    server.starttls()
    server.login('LOGIN','PSWD')
    
    for x in xrange(1,20):
        getTheCellName = "A%s" %x
        msg = MIMEMultipart()
        getTheCell = worksheet.acell(getTheCellName)
        getTheCellValue = getTheCell.value
        if getTheCellValue != "":
            server.sendmail('Sender-Email',getTheCellValue,'Mail-Content')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 2023-04-06
      • 2015-01-01
      • 2020-09-03
      相关资源
      最近更新 更多