2016-05-20 13 views
1
def email_page(request): 
    t = get_template('email.html') 
    email = EmailMessage('Hello', 'Test<br>break', '[email protected]',['[email protected]']) 
    email.content_subtype = "html" 

    workbook = xl.Workbook('ex.xlsx') 
    worksheet = workbook.add_worksheet() 
    worksheet.write(0, 0, 'Total') 
    workbook.close() 
    email.attach("ex.xlsx", workbook, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') 
    email.send() 
    return HttpResponse(t.render(Context({})), status=200) 

I tried the following changes on the email.attach line:メールのxlsxの添付ファイルジャンゴ

  • workbook.read() - 読みは、ブックworkbook.getvalue()

  • workbook.getvalue()の属性ではありません - のgetValueは属性ではありません'ファイル' オブジェクトのインデックス

をサポートしていません:例外TypeError - ワークブック

  • ワークブックの

  • 答えて

    1
    def email_page(request): 
        t = get_template('email.html') 
        email = EmailMessage('Hello', 'Test<br>break', '[email protected]',['[email protected]']) 
        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) 
    

    この方法でも、xlsxライターを使用してファイルを作成できます。

    関連する問題