Data Import & Export

Open Image URLs in Excel and Save Files with Product Codes

Elise WilliamsElise Williams Nov 20, 2026 868 views

Question details

Open image links stored in Excel and save the images in bulk using product codes as filenames.

Open Image URLs in Excel and Save Files with Product Codes
Product
Microsoft Excel and Google Drive
Device & OS
not provided
Scenario
A worksheet contains Google Drive image links and product codes, and the user needs to download and rename approximately 100 images.
Observed behavior
Shareable links normally open in a browser, but downloading and naming the files requires a separate workflow.
Before you start

Confirm which column contains the image links and that column B contains the corresponding product codes. Check that the files are accessible without signing in and that each link points to an individual image, not a folder.

Solution 1Recommended

Batch-download images using product codes

Use a Python script to download accessible image URLs and save each image with the product code from column B.

This example reads links from column A and product codes from column B, starting at row 2. It supports ordinary image URLs and common Google Drive file-sharing links; private files and links that return a Google Drive confirmation page require a different authenticated workflow.

1
Prepare the workbook

In Excel, place image links in column A and product codes in column B, with headers in row 1. Save the workbook as products.xlsx. Enter codes with leading zeros as text so they are preserved.

2
Install the required packages

Install Python, open a terminal, and run: python -m pip install openpyxl requests pillow

3
Create the download script

In a text editor, save the following as download_images.py in the same folder as products.xlsx: import re from io import BytesIO from pathlib import Path from urllib.parse import urlparse, parse_qs import requests from openpyxl import load_workbook from PIL import Image out = Path('images') out.mkdir(exist_ok=True) ws = load_workbook('products.xlsx', data_only=True).active extensions = {'JPEG': 'jpg', 'PNG': 'png', 'GIF': 'gif', 'WEBP': 'webp', 'BMP': 'bmp', 'TIFF': 'tif'} for row in ws.iter_rows(min_row=2): cell, code_cell = row[0], row[1] url = cell.hyperlink.target if cell.hyperlink else cell.value code = code_cell.value if not url or code is None: continue try: url = str(url).strip() parsed = urlparse(url) if parsed.hostname in ('drive.google.com', 'docs.google.com'): match = re.search(r'/file/d/([^/]+)', parsed.path) file_id = match.group(1) if match else parse_qs(parsed.query).get('id', [None])[0] if file_id: url = 'https://drive.google.com/uc?export=download&id=' + file_id response = requests.get(url, timeout=30) response.raise_for_status() image = Image.open(BytesIO(response.content)) image.verify() ext = extensions.get(image.format) if not ext: raise ValueError('Unsupported image format') name = re.sub(r'[\\/:*?"<>|\x00-\x1f]', '_', str(code)).strip(' .') if not name: raise ValueError('Empty filename') target = out / f'{name}.{ext}' if target.exists(): raise ValueError('Filename already exists') target.write_bytes(response.content) print(f'Row {cell.row}: saved {target}') except Exception as error: print(f'Row {cell.row}: {error}')

4
Run and review the download

In the terminal, change to the workbook folder and run python download_images.py. Open the images folder to review the files, and check the terminal for rows that failed or had duplicate filenames.

Batch-download images using product codes
Check link access: A link that works only when you are signed in may not work in the script. Google Drive may also return a confirmation page instead of an image. Review failed rows and use an authenticated download method where needed.
Free Microsoft Office alternative

Organize image links and product codes in WPS Spreadsheet

WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and support for Excel files, making it easy to move existing product lists. Use a separate automation tool to download and rename the linked images.

Organize image URLs alongside product codes in WPS SpreadsheetOpen and edit Microsoft Excel XLSX filesWork with a familiar spreadsheet interfaceUse a free, lightweight alternative for everyday office tasks
microsoft office alternative - wps office

Frequently Asked Questions

Can Excel download all linked images just by opening the hyperlinks?

No. Clicking a hyperlink normally opens it in a browser. To download and name many images, use a separate script or another automation tool.

Why does a Google Drive link work in my browser but fail in the script?

Your browser may be signed in, while the script makes an unauthenticated request. Check the file's sharing permissions in Google Drive; a confirmation page or restricted file may require an authenticated workflow.

How can I keep leading zeros in product-code filenames?

In Excel, format the product-code cells as Text before entering the codes. The script uses the stored cell value, not a numeric display format such as 00000.

What happens if two product codes produce the same filename?

The example script does not overwrite an existing file. It reports the row in the terminal so you can correct the code or choose a different naming convention.

Will the script put the images inside the worksheet?

No. It saves image files in an images folder beside the script. Embedding images in worksheet cells is a separate task.