首页 > 解决方案 > 将图表从 excel 导出到图像

问题描述

我一直在使用openpyxl在 linux 和 windows 平台上处理 xlsx 文件。但此时我需要阅读工作簿并将工作表中的图表导出为图像。我浏览了文档,但找不到任何方法来实现这一点。

问题:我可以使用或做什么来使用 python(最好是 openpyxl)将图表导出为图像?

标签: pythonexcelchartsopenpyxlxlsx

解决方案


我在阅读一些文档时发现了这一点https://pypi.org/project/openpyxl-image-loader/

如果你知道图像在哪里,你可以做

from openpyxl_image_loader import SheetImageLoader

# Load your workbook and sheet as you want, for example
wb = load_workbook('path_to_file.xlsx')
sheet = wb['required_sheet']

# Put your sheet in the loader
image_loader = SheetImageLoader(sheet)

# And get image from specified cell
image = image_loader.get('A3')

# Image now is a Pillow image, so you can do the following
image.show()

# Ask if there's an image in a cell
if image_loader.image_in('A4):
    print("Got it!")

如果您不确定图像在工作簿中的位置,您可以尝试遍历单元格,直到找到图像。


推荐阅读