Insert image in openpyxl

后端 未结 5 2023
不知归路
不知归路 2020-12-14 02:28

Is it possible to insert an image (jpeg, png, etc) using openpyxl?

Basically I want to place a generated image with a chart below it.

I don\'t see anything i

5条回答
  •  眼角桃花
    2020-12-14 02:51

    Just to add, I have been using openpyxl==2.5.6 (with Python3.65), and I had to use img.anchor('A1') instead of img.anchor(ws.cell('A1')).

    import openpyxl
    
    wb = openpyxl.Workbook()
    ws = wb.worksheets[0]
    img = openpyxl.drawing.Image('test.jpg')
    img.anchor('A1')
    ws.add_image(img)
    wb.save('out.xlsx')
    

提交回复
热议问题