콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
16177 화면

Hello, I associated with a button a method that allows the generation of an xlsx file, I would like to return the file just created, as for a normal file, with the Save as...

This is my code, I do not know how to write the return, I need help.

   @api.multi
    def export(self):
        workbook = xlsxwriter.Workbook('/tmp/test.xlsx')
        worksheet = workbook.add_worksheet()
        row = 0
        col = 0
        for vals in self.carrier_line_ids:
            worksheet.write(row, 0, vals.reference)
            ...
            ...
            row += 1


        workbook.close()
아바타
취소
작성자 베스트 답변

My solution:

@api.multi
    def export(self):
        file_name = 'temp'
        workbook = xlsxwriter.Workbook(file_name, {'in_memory': True})
        worksheet = workbook.add_worksheet()
        row = 0
        col = 0
        for e in header:
            worksheet.write(row, col, e)
            col += 1
        row += 1
        for vals in self.carrier_line_ids:
            worksheet.write(row, 0, vals.reference)
            ...
            ...
        workbook.close()
        with open(file_name, "rb") as file:
            file_base64 = base64.b64encode(file.read())
         self.carrier_xlsx_document_name = self.name + '.xlsx'
        self.write({'carrier_xlsx_document': file_base64, })

carrier_xlsx_document is a binary


view.xml

<field name="carrier_xlsx_document" widget="binary" filename="carrier_xlsx_document_name"
attrs="{'invisible':[('state','=', 'draft')]}" readonly="1"/>
<field name="carrier_xlsx_document_name" invisible="1"/>

Add to import xlsxwriter and base64

I hope this solution can help other programmers.

A request for mods: you can change the name of the thread and add SOLVED, I can't.

아바타
취소

Hi, I am trying this solution but I get the following error message:
FileNotFoundError: [Errno 2] No such file or directory: 'Registro_Ventas_12/2021.xlsx'
Do you know why is this happening?
This is my code:
def write_xlsx(self, file_name, header_list, field_list):
workbook = xlsxwriter.Workbook(file_name, {'in_memory': True})
worksheet = workbook.add_worksheet()
row = col = 0
# Write header row
for header in header_list:
worksheet.write(row, col, header)
col += 1
row += 1
# Write value rows
n = 1
for line in self.lcv_line_ids:
line_registry = self.env['lcv.line'].browse([line.id])
worksheet.write(row, 0, n)
col = 1
for field in field_list:
if isinstance(getattr(line_registry, field), float):
value = str(round(getattr(line_registry, field), 2))
else:
value = str(getattr(line_registry, field))
worksheet.write(row, col, value)
col += 1
n += 1
row += 1
workbook.close()
with open(file_name, "wb") as file:
file_base64 = base64.b64encode(file.read())
return file_base64

베스트 답변

I have no clue how to help you, but the forum software won't let me ask my question until I've answered other people's questions, so I'm going to go with a classic answer: paint ram's blood over your doorway.

아바타
취소
베스트 답변

Hi Paolo,

Go to,

Setting>>Translation>>Import/ Export>>Export Translation

The popup wizard generate the translation file and allow you to download the file.

This will give you an idea how you can make it to work with your module.

You will find the reference code inside base mdoule

I hope this will give you an idea, how you can hit the goal.

Rgds,

Anil.





아바타
취소
베스트 답변

Hi,

We have a written a blog about how to create XLS report in odoo 10, you can go through it: How to Create an XLS Report in Odoo ?


Thanks

아바타
취소
작성자

This does not help me, I create an xlsx file and I want it to be saved, for now I create it but I can not generate the window with a direct link to the file.

관련 게시물 답글 화면 활동
2
4월 24
22398
0
6월 23
3207
0
10월 20
3462
3
6월 20
9205
0
4월 16
6285