Extracting Hyperlink URL and TEXT into separate columns in excel

Imagine you're working with an Excel cell containing a hyperlink. This link might display inviting text like "Click Here," yet it directs you to a website, for instance, "https://www.bomshteyn.com", upon clicking.

Suppose you're interested in extracting this URL and anchor text as separate columns using an Excel formula. It's important to note that, as far as I'm aware, Excel doesn't offer a native function specifically for this task.

But this can be achieved using this small snippet of Python:

# Load the Excel file
new_file_path = '/mnt/data/test.xlsx'
new_wb = load_workbook(new_file_path)
new_sheet = new_wb.active

# Reinitialize lists to store publication names and URLs
new_publication_names = []
new_publication_urls = []

# Iterating through the cells in column B (excluding the header row) of the new file
for row in new_sheet.iter_rows(min_row=2, max_col=2):
    cell = row[0]  # Only the first column in the row
    new_publication_names.append(cell.value)
    new_publication_urls.append(cell.hyperlink.target if cell.hyperlink else None)

# Creating a new DataFrame with the extracted data
new_extracted_df = pd.DataFrame({
    'PUBLICATION_NAME': new_publication_names,
    'PUBLICATION_URL': new_publication_urls
})

new_extracted_df.head()

# Saving the extracted data to a new Excel file
output_file_path = '/mnt/data/extracted_publications.xlsx'
new_extracted_df.to_excel(output_file_path, index=False)

Selected work

All case studies

DWG · 1 · Distribution & Wholesale

A connected ERP for a wholesale distributor

We replaced a legacy desktop ERP with a portal for purchasing, receiving, inventory, sales and department workflows, connected to third-party warehouse inventory snapshots.

Before

  • Legacy desktop ERP used across departments
  • Historical records held in CSV files

Portal

  • Purchase orders, vendor offers and vendor bills
  • Receiving, discrepancy reports and per-container cost baselines
  • Inventory lots with FIFO and average landed cost
Read case study

DWG · 2 · Construction & Logistics

One logistics platform across multiple yards

We connected orders, dispatch, yard stock, drivers, equipment rentals and shipment-based invoicing for a construction supply business with multiple yards.

Before

  • Orders, deliveries and returns across multiple yards
  • Stock and backorders by warehouse

Portal

  • Orders and shipments with job-site deliveries and returns
  • Drivers, trucks and job sites with map picker and geocoding
  • Per-yard stock, movements, picking and backorder tracking
Read case study

DWG · 3 · Non-profit & Trusts

Donor management and receipting for charities

We built a donor platform that keeps each charity's branding and receipt sequence together with donations, CRA receipts, year-end packages and reporting.

Before

  • Donor and donation records across organizations
  • Receipt sequences and sender details

Portal

  • Organization branding, sender details and receipt sequences
  • Donors, donations, categories, campaigns and tags
  • Sequential CRA receipts, legacy flags and voided-receipt watermarks
Read case study