Insert image in openpyxl

后端 未结 5 2022
不知归路
不知归路 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:49

    This code worked for me:

    import openpyxl
    
    wb = openpyxl.Workbook()
    ws = wb.worksheets[0]
    ws.merge_cells('A1:A3')
    img = openpyxl.drawing.image.Image('image.jpg')
    row_number = 1
    col_idx = 1
    cell = ws.cell(row=row_number, column=col_idx)
    ws.add_image(img)
    wb.save('output.xlsx')
    

提交回复
热议问题