我一直在尝试使用xlwings将excel工作表转换为pdf。我得到它的工作,但我不能更新所有链接自动没有得到这个错误。我需要在不提示用户更新的情况下更新工作表。任何人都知道如何在不出错的情况下解决此问题。这是我的代码:
def create_report(name):
if len(name) > 30:
name = name[0:30]
wb = xw.Book("Individual Supplier Report Cards.xlsx", update_links = all)
sheet = wb.sheets[name]
current_work_dir = os.getcwd()
pdf_path = os.path.join(current_work_dir, "Report Card.pdf")
sheet.api.ExportAsFixedFormat(0, pdf_path)
os.startfile(pdf_path)
这就是我得到的错误:
ret = self._oleobj_.InvokeTypes(0, LCID, 2, (9, 0), ((12, 1),),Index
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147352565), None)
编辑:
转换成pdf是可行的,但当它从我的电子邮件功能,我得到相同的错误。有人知道这里有什么问题吗?这是我的密码:
def send_email(contact_list):
for email, name in contact_list.items():
if email == "[no contact]":
continue
msg = MIMEMultipart("alternative")
msg['From']= "xxxx"
msg['To']= email
msg['Subject']= "xxxx"
message = open("Message template.txt", "r")
str1 = ""
for line in message:
str1 = str1 + line
message.close()
message1 = MIMEText(str1)
msg.attach(message1)
create_report(name)
pdfname = "Report Card.pdf"
binary_pdf = open(pdfname, 'rb')
payload = MIMEBase('application', 'octate-stream', Name=pdfname)
payload.set_payload((binary_pdf).read())
binary_pdf.close()
encoders.encode_base64(payload)
payload.add_header('Content-Decomposition', 'attachment', filename=pdfname)
msg.attach(payload)
s = smtplib.SMTP_SSL(host='smtp.gmail.com')
s.login("xxx", "xxx")
s.send_message(msg)
s.quit
del msg
暂无答案!
目前还没有任何答案,快来回答吧!