File size: 1,604 Bytes
9a8b10b f566386 9a8b10b 3d58410 9a8b10b 3d58410 9a8b10b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from openpyxl import load_workbook from openpyxl.drawing.image import Image def read_images_from_excel(file_path, filter_column): # Load the workbook wb = load_workbook(filename=file_path) # Iterate through each sheet in the workbook for sheet_name in wb.sheetnames: sheet = wb[sheet_name] # Find the column index of the filter column filter_column_index = None for col in range(1, sheet.max_column + 1): if sheet.cell(row=1, column=col).value == filter_column: filter_column_index = col break if filter_column_index is None: print(f"Filter column '{filter_column}' not found in sheet '{sheet_name}'") continue # Iterate through each row in the sheet for row in range(2, sheet.max_row + 1): # Check if the filter condition is met if sheet.cell(row=row, column=filter_column_index).value == "your_filter_value": # Iterate through each image in the row for image in sheet._images: # Check if the image is in the same row as the filter condition if image.anchor._from.row == row: # Get the image data img_data = image.image # You can process the image data here # For example, you can save the image to a file img_data.save(f"{sheet_name}_{row}_{image.anchor._from.col}.png") # Example usage: read_images_from_excel("example.xlsx", "Column F") |