Images dissapear in excel documents when copying them with python

后端 未结 3 1904
南方客
南方客 2021-01-13 11:26
import openpyxl

def factuur():
    wb = openpyxl.load_workbook(\'factuurvoorbeeld1.xlsx\')
    Blad1 = wb.active
    Blad1[\'K7\'] = \'logo.png\'
    Blad1[\'E22\']         


        
3条回答
  •  无人及你
    2021-01-13 11:48

    I face same issue with openpyxl 2.6.2

    Logo images was added in template excel file but disappear in exported .xlsx file

    I just install Pillow and now its exporting all images fine.

    pip install Pillow
    

    This is my sample code to create salary slip from template excel file:

    from openpyxl import load_workbook
    
    
    def create_salary_slip():
        wb = load_workbook(filename = 'salary.xlsx')
        # grab the active worksheet
        ws = wb.active
        # Add Income
        ws['D11'] = 25000
        # Add deduction
        ws['M11'] = 1500
        # Save the file
        wb.save("sample.xlsx")
    
    create_salary_slip()
    

提交回复
热议问题