2016-11-17 36 views

回答

2

您可以保存您的工作簿对象到BytesIO实例(从IO进口BytesIO)

output = BytesIO() 
workbook.save(output) 

然后可以使用Django的EmailMessage类来创建你的电子邮件,并附上您的BytesIO对象作为文件作为第二个参数。

email = EmailMessage(
    'Hello', 
    'Body goes here', 
    '[email protected]', 
    ['[email protected]', '[email protected]'], 
    ['[email protected]'], 
    reply_to=['[email protected]'], 
    headers={'Message-ID': 'foo'}, 
) 

email.attach('file.xlsx', output.getvalue() , 'application/vnd.ms-excel') 

请查看如何要求下一次:)

相关问题