adfasda
adfasda
da(f"Error processing image {counter} from {source}: {e}")
print(f"Error processing image {counter} from {source}: {e}")
return False
# Method 1: Extract images using openpyxl
def extract_with_openpyxl():
global image_counter
try:
wb = openpyxl.load_workbook(excel_path)
ws = wb.active
logging.info("Excel file loaded successfully with openpyxl")
print("Excel file loaded successfully with openpyxl")
# Get all images
images = ws._images
logging.info(f"Found {len(images)} embedded images with openpyxl")
print(f"Found {len(images)} embedded images")
if not images:
logging.warning("No embedded images found with openpyxl")
print("No embedded images found with openpyxl")
return
for img in images:
try:
img_data = img._data()
image = Image.open(io.BytesIO(img_data))
if process_image(image, image_counter, "openpyxl"):
image_counter += 1
except Exception as e:
logging.error(f"Error processing openpyxl image {image_counter}: {e}")
print(f"Error with openpyxl image {image_counter}: {e}")
except Exception as e:
logging.error(f"Failed to load Excel file with openpyxl: {e}")
print(f"Error loading Excel file with openpyxl: {e}")
# Method 2: Extract images by treating .xlsx as a ZIP arc