pip install xlwings ;
xlwings-0.28.5-cp37-cp37m-win_amd64.whl (1.6 MB)
摘要:Make Excel fly: Interact with Excel from Python and vice versa.
Requires: pywin32
编写 xlwings_test.py 如下
# -*- coding: utf-8 -*-
""" xlwings 结合 Matplotlib 运用,能将图片加入 Excel文件中"""
import matplotlib.pyplot as plt
import xlwings as xw
fig = plt.figure() # 指定画布
# plt.plot([1, 2, 3, 4, 5])
plt.plot([36,5,3,25,78])
plt.plot([9,10,31,45])
plt.plot([6,14,45,31])
plt.savefig(r'd:\python\test.png')
book = xw.Book(r'D:/python/test.xlsx')
sheet = book.sheets[0]
#help(sheet.pictures)
#add(self, image, link_to_file=False, save_with_document=True,
# left=None, top=None, width=None, height=None, name=None, update=False,
# scale=None, format=None, anchor=None, export_options=None)
sheet.pictures.add(fig, left=100, top=100, name='mypic', update=True)
book.save(r'd:\python\test.xlsx')
book.close()
运行 python xlwings_test.py&n

文章介绍了如何使用Python库xlwings将Matplotlib生成的图片插入Excel文件,并提到了openpyxl库用于处理xlsx文件时插入图片的功能。
最低0.47元/天 解锁文章
4231

被折叠的 条评论
为什么被折叠?



