تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4905 أدوات العرض

Hello All,

I generate xlsx report for list of customers and my report generated according to individual customer wise means for 4 customer 4 sheets generated. But, i want single sheet for multiple customers list.

my code and screenshots are here:

from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx

class PartnerXlsx(ReportXlsx):
    def generate_xlsx_report(self, workbook, data, partners):
        for obj in partners:
            report_name = obj.name
            print("REPRTTTTTTT", report_name, report_name[:31])
            # One sheet by partner
            sheet = workbook.add_worksheet(report_name[:31])
            bold = workbook.add_format({'bold': True})
            sheet.write(0, 0, obj.name, bold)
            sheet.write(0, 1, obj.email, bold)
            sheet.write(0, 2, obj.telephone, bold)
PartnerXlsx('report.res.partner.xlsx', 'res.partner')


5 sheets generated for 5 customers


Requirement: One sheet for all user



Thanks in advance.

الصورة الرمزية
إهمال
أفضل إجابة

Hi Pawan,

You're adding a worksheet per contact in your for loop over the partners. If you move that part outside of the for loop it will add all partners in one single page. You where also setting the format again for every single contact. This should work:

from odoo.addons.report_xlsx.report.report_xlsx import ReportXlsx

class PartnerXlsx(ReportXlsx):
    def generate_xlsx_report(self, workbook, data, partners):
	    report_name = obj.name
        print("REPRTTTTTTT", report_name, report_name[:31])
        # One sheet by partner
        sheet = workbook.add_worksheet(report_name[:31])
        bold = workbook.add_format({'bold': True})
        index = 0
        for obj in partners:
            sheet.write(index, 0, obj.name, bold)
            sheet.write(index, 1, obj.email, bold)
            sheet.write(index, 2, obj.telephone, bold)
            index +=1
PartnerXlsx('report.res.partner.xlsx', 'res.partner')

Note: You're writing on row "0" every time with sheet.write(0). You might want to add an index/counter to the function and use this as I've did in this code.

Regards,
Yenthe

الصورة الرمزية
إهمال
الكاتب

Hello Yenthe,

Now, i am getting only single sheet but show only single row(last record). I think some append condition missing in above code.

Hi Pawan, I see your issue. You keep setting the values on the first row (sheet.write(0)) always applies on the first. Add an index to it.

I've updated the code to reflect that too.

الكاتب

Thanks Yenthe,

i updated code with "for index, obj in enumerate(partners):"

You're welcome, best of luck!

الكاتب

Thanks...

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مايو 23
66
0
أغسطس 22
2399
1
يوليو 22
20102
0
أبريل 22
3069
3
سبتمبر 21
3240