[Answered ]-Email xlsx attachment Django

2👍

def email_page(request):
    t = get_template('email.html')
    email = EmailMessage('Hello', 'Test<br>break', 'email@hotmail.com',['email@hotmail.com'])
    email.content_subtype = "html"
    f = StringIO.StringIO() # create a file-like object 
    workbook = xl.Workbook(f)
    worksheet = workbook.add_worksheet()
    worksheet.write(0, 0, 'Total')
    workbook.close()
    email.attach("b.xlsx", f.getvalue(), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    email.send()
    return HttpResponse(t.render(Context({})), status=200)

This way we can still use xlsx writer to make the file.

👤Helpme

Leave a comment