使用XLWINGS.pictures.add()将图片插入特定的工作表和单元格



我正试图从pyplot生成一个图像,并使用xlwings将该图像放置在Excel中特定工作表的特定单元格中。我已经成功地生成了图像并将其放置在工作表上,但我的意图是将多个图像放置在工作单上的不同位置。

这是我生成图像的代码:

#Plotting the bell-shaped curve for Critical Care
plt.style.use('seaborn')
ccfig = plt.figure(figsize=(6, 6))
plt.plot(cc_ndist, cc_normpdf, color='black', linestyle='dashed')
plt.scatter(cc_ndist, cc_normpdf, marker='o', s=25, color='gold')

# open an existing Excel workbook with existing empty worksheet(s)
wb = xw.Book(.....Score_2022_Q1.xlsb')
ws1 = wb.sheets['Metrics']
ws2 = wb.sheets['Critical Care']
# add figures to the workbook
ws2.pictures.add(ccfig, name='CC Plot', update=True)

有没有办法在.pictures.add((或工作表的变量中定义单元格位置?

# adding left and top for the correct syntax to place the picture at cell "B2"
ws2.pictures.add(ccfig, name='CC Plot', update=True, 
left=ws2.range('B5').left, top=ws2.range('B5').top)

相关内容

最新更新