Can I insert matplotlib graphs into Excel programmatically?

后端 未结 3 1660
不思量自难忘°
不思量自难忘° 2020-12-03 14:22

I am saving matplotlib files as .tiff images. I\'d like to be able to then open an excel file and paste the image there.

openpyxl doesnot seem to support image embed

3条回答
  •  甜味超标
    2020-12-03 15:03

    This worked out for me:

    import openpyxl
    
    wb = openpyxl.load_workbook('input.xlsx')
    ws = wb.active
    
    img = openpyxl.drawing.image.Image('myplot.png')
    ws.add_image(ws.cell('A1'))
    
    ws.save('output.xlsx')
    

提交回复
热议问题