Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5531 Lượt xem

I generate XLSX file using xlsxwriter module and downloaded after generated, but what I need is to save the xlsx file in the attachment? #odoo 15


Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you Jainesh,

I couldn't reply to your answer because of this stupid Karma. So your answer was helpful and inspired me to find the solution, but it will not work on Python 3, the following code is worked on Python 3:


from io import BytesIO

import base64

import xlsxwriter


        output = BytesIO()

        file_name = "%s.xlsx” % your_file_name

        workbook = xlsxwriter.Workbook(output)


        //your code here


        self.env['ir.attachment'].create({

            'name': file_name,

            'type': 'binary',

            'datas': datas,

            'store_fname': file_name,

            'res_model': model_name,

            'res_id': res_id,

            'mimetype': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

        })





Câu trả lời hay nhất

Hello Saleh Algarni

Hope this code block will work for you.

Please find code in Comment. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Ảnh đại diện
Huỷ bỏ

from cStringIO import StringIO
import base64

workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 20)

# Code for XLSX

fp = StringIO()
workbook.save(fp)
fp.seek(0)
datas = base64.encodestring(fp.read())
file_name = "demo.xlsx"
attachment_data = {
'name':file_name,
'datas_fname':file_name,
'datas':datas,
'res_model':"modelname",
}
self.env['ir.attachment'].create(attachment_data)

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 22
1994
1
thg 2 25
1074
1
thg 5 23
4026
1
thg 7 19
4864
2
thg 6 23
8699