Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何更好地使用IF将pdf文件附加到Outlook?_Python_Excel_Win32com - Fatal编程技术网

Python 如何更好地使用IF将pdf文件附加到Outlook?

Python 如何更好地使用IF将pdf文件附加到Outlook?,python,excel,win32com,Python,Excel,Win32com,我正在开发一个应用程序,自动创建我所在公司收集部门的电子邮件。挖掘互联网我能够执行以下步骤,访问电子表格,用数据创建列表,并使用win32com库将电子邮件保存在草稿中。我的问题是,我如何才能通过if(如果此文件夹中有一个与codigos编号相同的文件,则将其附加到电子邮件)将账单附加到电子邮件中 代码如下: import csv import os.path import time import win32com.client as client import openpyxl # Open

我正在开发一个应用程序,自动创建我所在公司收集部门的电子邮件。挖掘互联网我能够执行以下步骤,访问电子表格,用数据创建列表,并使用
win32com
库将电子邮件保存在草稿中。我的问题是,我如何才能通过
if
(如果此文件夹中有一个与
codigos
编号相同的文件,则将其附加到电子邮件)将账单附加到电子邮件中

代码如下:

import csv
import os.path
import time
import win32com.client as client
import openpyxl

# Opens the spreadsheet and obtains the status of the last payment.

wb = openpyxl.load_workbook('./lib/cobranca3.xlsx')
sheet = wb['Sheet1']

lastCol = sheet.max_column

# Checks the payment status of each customer.

unpaidMembers = {}
codigos = []
clients = []
cnpjs = []
emails = []
vencimentos = []
valores = []
acrescimos = []
antecipacoes = []
descontos = []
months = []

for r in range(2, sheet.max_row + 1):

    codigo = sheet.cell(row=r, column=1).value
    cliente = sheet.cell(row=r, column=2).value
    cnpj = sheet.cell(row=r, column=3).value
    email = sheet.cell(row=r, column=4).value
    venc = sheet.cell(row=r, column=6).value
    valor = sheet.cell(row=r, column=7).value
    acresc = sheet.cell(row=r, column=8).value
    antec = sheet.cell(row=r, column=9).value
    desc = sheet.cell(row=r, column=10).value
    codigos.append(codigo)
    clients.append(cliente)
    cnpjs.append(cnpj)
    emails.append(email)
    vencimentos.append(venc)
    valores.append(valor)
    unpaidMembers[cliente] = email
    #print('Line:', r, 'Column:', c, 'Código:', codigo, 'Client:', cliente, 'CNPJ:', cnpj, 'Email:', email, 'Vencimento:', venc, 'Valor:', (valor + acresc) - antec - desc, 'Month:', month)
    #print('dictionary created successfully')


template = """
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
    </head>
    <body>
        <table style="background-color: #084d6e; width: 700px;">
            <tr>
                <td style="width: 700px; padding: 10px; color: rgb(163, 134, 78); background-color: #084d6e; text-align: center; font-size: 18px; font-weight: 800; font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;">HONORÁRIO CONTÁBIL</td>
            </tr>
        </table>
    </body>
</html>
"""
outlook = client.Dispatch('Outlook.Application')
for cliente, email in zip(clients, emails):
    message = outlook.CreateItem(0)
    message.To = email
    message.Subject = '{} - HONORÁRIO EM ABERTO - MÊS: /2021' .format(cliente)
    message.HTMLBody = template
    message.save()
导入csv
导入操作系统路径
导入时间
将win32com.client作为客户端导入
导入openpyxl
#打开电子表格并获取上次付款的状态。
wb=openpyxl.load_工作簿('./lib/cobranca3.xlsx')
工作表=工作表['Sheet1']
lastCol=sheet.max\u列
#检查每个客户的付款状态。
UNPAIDEMBERS={}
codigos=[]
客户=[]
cnpjs=[]
电子邮件=[]
vencimentos=[]
瓦洛雷斯=[]
acrescimos=[]
antecipacoes=[]
descontos=[]
月份=[]
对于范围内的r(2,sheet.max_行+1):
codigo=sheet.cell(行=r,列=1).value
cliente=sheet.cell(行=r,列=2).value
cnpj=表.单元(行=r,列=3).值
email=sheet.cell(行=r,列=4).值
venc=表单元格(行=r,列=6).值
valor=表.单元格(行=r,列=7).值
acresc=工作表单元格(行=r,列=8).值
antec=sheet.cell(行=r,列=9).value
desc=表.单元(行=r,列=10).值
codigos.append(codigo)
clients.append(客户)
cnpjs.append(cnpj)
电子邮件。附加(电子邮件)
vencimentos.append(venc)
附加(valor)
UNPAIDEMBERS[客户]=电子邮件
#打印('Line:',r,'Column:',c,'código:',codigo,'Client:',cliente,'CNPJ:',CNPJ,'Email:',Email,'Vencimento:',venc,'Valor:',(Valor+acresc)-antec-desc,'Month:',Month)
#打印('已成功创建词典')
模板=“”“
里约热内卢荣誉酒店
"""
outlook=client.Dispatch('outlook.Application')
对于客户,使用zip发送电子邮件(客户,电子邮件):
message=outlook.CreateItem(0)
message.To=电子邮件
message.Subject='{}-HONORÁRIO EM ABERTO-MÊS:/2021'。格式(客户)
message.HTMLBody=模板
message.save()
使用的电子表格模型: