İçeriğe geç
KAMPANYA Kurumsal Web Paketi — $499'dan başlayan fiyatlar Web & Logo Tasarımı · Kurumsal E-posta · LiteSpeed + CloudLinux · Imunify360 Güvenlik · cPanel Yönetim · 3 Gbps DDoS Koruması 00 Gün 00 Saat 00 Dk 00 Sn
AIOR

Converting Text to URL in Excel Using Python — A Practical Automation Walkth

Sektör topluluğu — sorularınız, deneyimleriniz ve duyurularınız için.

Converting Text to URL in Excel Using Python — A Practical Automation Walkth

Aior

Administrator
Staff member
Joined
Apr 2, 2023
Messages
895
Reaction score
2
Points
18
Age
40
Location
Turkey
Website
aior.com
1/3
Thread owner

Senaryo​

Bir Excel dosyasında düz metin olarak yazılmış domain isimleri var ve hepsini tıklanabilir HTTPS URL'lerine çevirip ayrı bir dosyaya kaydetmek istiyorsunuz. Bu işi elle yapmak küçük listelerde mantıklı, ancak yüzlerce satıra ulaşan iş yüklerinde Python ve openpyxl kütüphanesi otomasyonu çok daha temiz, hızlı ve hatasızdır.

Bu rehber AIOR ekibinin domain portföyü gibi büyük listelerle çalışırken kullandığı pratik bir yöntemi paylaşır.

Hazırlık​

Anaconda Python dağıtımı ve Jupyter Notebook kullanacağız. Bunlar yoksa pip ile ana paketleri kurmak yeterlidir:

Code:
pip install openpyxl pandas

Örnek girdi dosyası (domains.xlsx) bir sütunda domain adı tutuyor:

Code:
A1: domain
A2: aior.com
A3: example.com
A4: docs.python.org

Python Scripti​

Aşağıdaki kısa script girdi dosyasını okur, her hücreyi https:// ön eki ekleyerek dönüştürür ve domains_with_url.xlsx olarak kaydeder:

Code:
import openpyxl

src = openpyxl.load_workbook("domains.xlsx")
ws = src.active

for row in ws.iter_rows(min_row=2):
    cell = row[0]
    if cell.value and not str(cell.value).startswith("http"):
        cell.value = "https://" + str(cell.value).strip()

src.save("domains_with_url.xlsx")
print("OK — yeni dosya kaydedildi")

Açıklamalar​

iter_rows(min_row=2) başlık satırını atlayarak veri satırlarından başlar. cell.value mevcut hücre içeriğidir; başında "http" yoksa öne https:// eklenir. Bu kontrol, dosyada zaten URL formatında olan kayıtların tekrar prefix almasını önler. Dönüşüm sonrası yeni dosya ayrı kaydedilir; orijinal dosya bozulmaz.

Çıktıyı Tıklanabilir Yapma​

Excel'de URL'leri yalnızca metin olarak kaydetmek yeterli değildir; bağlantıların tıklanabilir olması için openpyxl'in Hyperlink sınıfı kullanılır:

Code:
from openpyxl.worksheet.hyperlink import Hyperlink

for row in ws.iter_rows(min_row=2):
    cell = row[0]
    url = "https://" + str(cell.value).strip()
    cell.value = url
    cell.hyperlink = Hyperlink(ref=cell.coordinate, target=url)
    cell.style = "Hyperlink"

Bu sayede dosya Excel'de açıldığında her hücre mavi renkte, altı çizili ve tıklanabilir bağlantı haline gelir.

Büyük Dosyalar İçin Pandas​

On binlerce satırlık iş yüklerinde pandas daha hızlı çalışır:

Code:
import pandas as pd
df = pd.read_excel("domains.xlsx")
df["url"] = "https://" + df["domain"].astype(str).str.strip()
df.to_excel("domains_with_url.xlsx", index=False)

Pandas tüm sütunu vektörize tek seferde işler, döngü maliyeti yoktur.

Yaygın Hatalar​

"BadZipFile" hatası: dosya .xls (eski format) olabilir, .xlsx'e dönüştürün. "Permission denied": çıktı dosyası başka uygulamada (örn. Excel) açık olabilir, kapatın. Yanlış sütun: iter_rows'da kullandığınız row[0] ilk sütunu işaret eder; farklı bir sütun için indeks ayarlayın.

AIOR olarak müşterilerimizin domain portföy yönetimi ve toplu URL işleme ihtiyaçlarında bu tür otomasyon scriptlerini paket halinde de sunuyoruz.


The Scenario​

You have an Excel file with domain names stored as plain text and want to convert each one into a clickable HTTPS URL, then save it as a separate file. For small lists doing this by hand makes sense, but for hundreds of rows Python with openpyxl is much faster, cleaner and less error-prone.

This guide shares the practical workflow the AIOR team uses for domain-portfolio-scale operations.

Preparation​

We'll use Anaconda Python with Jupyter Notebook. If you don't have them, plain pip works too:

Code:
pip install openpyxl pandas

The sample input file (domains.xlsx) holds domain names in one column:

Code:
A1: domain
A2: aior.com
A3: example.com
A4: docs.python.org

The Python Script​

This short script reads the input file, prefixes each cell with https:// and saves the result as domains_with_url.xlsx:

Code:
import openpyxl

src = openpyxl.load_workbook("domains.xlsx")
ws = src.active

for row in ws.iter_rows(min_row=2):
    cell = row[0]
    if cell.value and not str(cell.value).startswith("http"):
        cell.value = "https://" + str(cell.value).strip()

src.save("domains_with_url.xlsx")
print("OK — new file saved")

How It Works​

iter_rows(min_row=2) skips the header row and starts iterating from the data rows. cell.value is the current cell content; if it doesn't already start with "http", we prefix https://. This guard prevents re-prefixing rows that are already proper URLs. The transformed result saves to a new file, leaving the original intact.

Making Cells Clickable​

Saving URLs as plain text isn't enough — to make them actual clickable hyperlinks, use openpyxl's Hyperlink class:

Code:
from openpyxl.worksheet.hyperlink import Hyperlink

for row in ws.iter_rows(min_row=2):
    cell = row[0]
    url = "https://" + str(cell.value).strip()
    cell.value = url
    cell.hyperlink = Hyperlink(ref=cell.coordinate, target=url)
    cell.style = "Hyperlink"

Now each cell renders blue, underlined and clickable when the file opens in Excel.

Pandas for Large Files​

For very large datasets (tens of thousands of rows), pandas is faster:

Code:
import pandas as pd
df = pd.read_excel("domains.xlsx")
df["url"] = "https://" + df["domain"].astype(str).str.strip()
df.to_excel("domains_with_url.xlsx", index=False)

Pandas vectorises the whole column in one pass, eliminating per-cell loop overhead.

Common Errors​

"BadZipFile" error: the file might be the older .xls format — convert it to .xlsx first. "Permission denied": the output file is probably open in another app (e.g. Excel itself); close it. Wrong column: row[0] in the loop points at the first column; adjust the index if your domain column is elsewhere.

At AIOR we offer domain portfolio management and bulk-URL automation scripts as part of our service packages.
 

Attachments

Last edited:

Forum statistics

Threads
891
Messages
898
Members
27
Latest member
AIORAli

Members online

No members online now.

Featured content

AIOR
AIOR TEKNOLOJİ

Tüm ihtiyaçlarınız için Teklif alın

Hosting · Domain · Sunucu · Tasarım · Yazılım · Mühendislik · Sektörel Çözümler

Teklif al

7/24 Destek · Anında yanıt

Back
Top