Skip to content

Instantly share code, notes, and snippets.

@suqingdong
Created June 24, 2025 03:31
Show Gist options
  • Select an option

  • Save suqingdong/afbead6aebd1e3a0f1bbe60680d5226f to your computer and use it in GitHub Desktop.

Select an option

Save suqingdong/afbead6aebd1e3a0f1bbe60680d5226f to your computer and use it in GitHub Desktop.
Python读取Excel单元格图像
import openpyxl
from PIL import Image
wb = openpyxl.load_workbook('test.xlsx')
ws = wb.active
for image in ws._images:
anchor = image.anchor
if hasattr(anchor, '_from'):
row = anchor._from.row + 1
col = anchor._from.col + 1
cell_address = ws.cell(row=row, column=col).coordinate
print("图片位置:", cell_address)
im = Image.open(image.ref)
im.save(f'image_from_{cell_address}.png')
import openpyxl
from openpyxl_image_loader import SheetImageLoader
wb = openpyxl.load_workbook('test.xlsx')
ws = wb.active
image_loader = SheetImageLoader(ws)
if image_loader.image_in('B7'):
print("Image found in cell B7")
image = image_loader.get('B7')
image.save('image_from_B7.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment