Extracting zip file with unzip activity

Hello community !

Iam using Extract unzip activity to extract the files…But when iam extracting the files using unzip activity it is extracting only pdf’s from that zip files…And that zip files contains excel also.
For example : There are 4 zip files and and all 4 zip contains pdf’s and excel files after extracting all zip’s it is extracting 4 pdf’s and only one excel…And when iam enabling the dedicated folder option then in that folder iam getting both the file’s…

@Priyesh_Shetty

It might be because the same files might be existing already

check on the same

cheers

@Anil_G there are different diffrent zip files
The name is like this-SURV76543,SURV56789

And that excel file name is Same in every zip’s Anexure.xlsx like this it has name

@Priyesh_Shetty

because the filenames are same it is nt extracting I believe…use different folders to extract

when name i same it is skipping the extraction

cheers

@Anil_G actually in this process bot is going to a website and if it found that file’s it is downloading the file’s and it is in zip format so in that every zip’s there are 2 files one is pdf and another is xlsx…so i can’t download different folder…and once the file get extracted i want to attach all the pdf and excel file in mail body and i have to mail it.

@Anil_G when iam using extract to dedicated folder option enabled in that activity then iam getting all the files in that folder’s but how can i get file’s from all that dedicated folder’s?

from openpyxl import load_workbook
from openpyxl.drawing.image import Image
from io import BytesIO

def extract_embedded_files(excel_file):
# Load the workbook
wb = load_workbook(excel_file, read_only=True, keep_links=False)

# List to store extracted file names
extracted_files = []

# Iterate through all worksheets
for sheetname in wb.sheetnames:
    ws = wb[sheetname]

    # Iterate through all drawings (images)
    for drawing in ws._images:
        img = drawing.image

        # Extract image data as bytes
        img_bytes = img.bytes

        # Store or process the image bytes as needed
        extracted_files.append({
            'sheet': sheetname,
            'filename': img.filename,
            'image_data': img_bytes
        })

# Close workbook
wb.close()

return extracted_files

Example usage:

if name == “main”:
excel_file_path = ‘sample.xlsx’

# Extract embedded files from Excel
extracted_files = extract_embedded_files(excel_file_path)

# Save extracted images to files or process them further
for file_info in extracted_files:
    filename = file_info['filename']
    image_data = file_info['image_data']
    
    # Example: save each image to a file
    with open(filename, 'wb') as f:
        f.write(image_data)
        print(f"Extracted {filename}")

print("Extraction complete.")