Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
22755 Widoki

Hello All,

I am creating excel report using python xlwt. When i add the image in it, it gives me error.

Error :-

IOError: [Errno 36] File name too long:


Edited Code :-

@api.multi

def print_excel_report(self):

     filename= 'Products.xls'

     workbook= xlwt.Workbook(encoding="UTF-8")


     if self.product_line:

        worksheet= workbook.add_sheet('products')       

        font = xlwt.Font()       

        font.bold = True

         for_left = xlwt.easyxf("font: bold 1, color black; borders: top double, bottom double, left double, right double; align: horiz left")       

        for_left_not_bold = xlwt.easyxf("font: color black; borders: top double, bottom double, left double, right double; align: horiz left")       

        for_center_bold = xlwt.easyxf("font: bold 1, color black; align: horiz center")

        GREEN_TABLE_HEADER = xlwt.easyxf(             

                                        'font: bold 1, name Tahoma, height 250;'                

                                        'align: vertical center, horizontal center, wrap on;'                

                                        'borders: top double, bottom double, left double, right double;'                

                                        'pattern: pattern solid, pattern_fore_colour blue, pattern_back_colour dark_red_ega'                                                         )       

        style = xlwt.easyxf('font:height 400, bold True, name Arial; align: horiz center, vert center;borders: top medium,right medium,bottom medium,left medium')
        alignment = xlwt.Alignment()

        alignment.horz = xlwt.Alignment.HORZ_RIGHT       

        style = xlwt.easyxf('align: wrap yes')       

        style.num_format_str = '0.00'


        worksheet.row(0).height = 320       

        worksheet.col(0).width = 2000       

        worksheet.col(1).width = 2000       

        borders = xlwt.Borders()

        borders.bottom = xlwt.Borders.MEDIUM       

        border_style = xlwt.XFStyle()

        border_style.borders = borders
        worksheet.write_merge(0,1,0,9,'Product',GREEN_TABLE_HEADER)


        row = 3       

        worksheet.write(row, 0, 'Name', for_left)       

        worksheet.write(row, 1, 'Image', for_left)       

        worksheet.write(row, 2, 'Price', for_left)


        for product in self.product_line:
            row = row+1           

            worksheet.write(row, 0, product.name or '',for_left_not_bold)           

            worksheet.write(row, 1, product.image_medium or '',for_left_not_bold)           

            worksheet.write(row, 2, product.list_price or '',for_left_not_bold)


     fp = StringIO()   

    workbook.save(fp)

     export_id = self.pool.get('excel.extended').create(self._cr, self._uid, {'excel_file': base64.encodestring(fp.getvalue()), 'file_name': filename}, context=self._context)   

    fp.close()



How to solve this or how to add image in the excel file ?

Any suggestion from is appreciated.


Thanks in advance.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi Jignesh Mehta

Read how you can solve that here:

https://www.odoo.com/es_ES/forum/ayuda-1/question/add-signature-image-stored-in-database-to-excel-file-91361#answer-91367

Awatar
Odrzuć
Autor

Hello @Axel Mendoza, I am not using openpyxl for creating xls report. I want to insert image using xlwt. I have added the method for creating xls report. Thanks,

Those posts talk about the problem of generating an xlwt report using an inmemory image data that it's not suitable with xlwt because it's not allow you to pass a file-like object, it just work with filenames for that, at least in previous versions, so if you wanna do that you should save the image on a temp file to pass the filename to xlwt, as my answer suggest in that thread

Hope you solve it

Powiązane posty Odpowiedzi Widoki Czynność
1
lip 21
176
0
kwi 21
331
2
gru 24
5939
0
sie 19
2791
4
sie 19
4072