From c8628e1fe891f2bf9b18b09fe3a3244779267d1c Mon Sep 17 00:00:00 2001 From: Shaun2006 <116490490+shaun2006@users.noreply.github.com> Date: Sun, 15 Feb 2026 19:48:50 +0530 Subject: [PATCH 1/2] Added a script that can conver vcf contacts file to excle, which then you can edit as you want to --- VCF to Excle/README.md | 53 ++++++++++++++++++++++++++++++ VCF to Excle/sample.vcf | 25 +++++++++++++++ VCF to Excle/vfc-to-excle.py | 62 ++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 VCF to Excle/README.md create mode 100644 VCF to Excle/sample.vcf create mode 100644 VCF to Excle/vfc-to-excle.py diff --git a/VCF to Excle/README.md b/VCF to Excle/README.md new file mode 100644 index 00000000..748b621c --- /dev/null +++ b/VCF to Excle/README.md @@ -0,0 +1,53 @@ +# VCF to Excel Converter + +A simple Python script to convert a `.vcf` (vCard) file into an Excel `.xlsx` file. + +## Requirements + +- Python 3.x +- pandas +- openpyxl + +Install required packages: + +```bash +pip install pandas openpyxl +``` + +## Usage + +Run the script from the command line: + +```bash +python vcf_to_excel.py input.vcf -o output.xlsx +``` + +If you do not provide the `-o` option, the script will automatically create an Excel file with the same name as the input file. + +Example: + +```bash +python vcf_to_excel.py contacts.vcf +``` + +This will create: + +``` +contacts.xlsx +``` + +## Extracted Fields + +The script extracts the following fields from the VCF file: + +- Full Name +- Phone Numbers +- Emails +- Organization +- Address + +## Notes + +- Multiple phone numbers and emails are combined into a single cell separated by commas. +- The input file must be a valid `.vcf` file. + diff --git a/VCF to Excle/sample.vcf b/VCF to Excle/sample.vcf new file mode 100644 index 00000000..76f86d46 --- /dev/null +++ b/VCF to Excle/sample.vcf @@ -0,0 +1,25 @@ +BEGIN:VCARD +VERSION:3.0 +N:Doe;John;;; +FN:John Doe +ORG:Example.com Inc.; +TITLE:Imaginary test person +EMAIL;type=INTERNET;type=WORK;type=pref:johnDoe@example.org +TEL;type=WORK;type=pref:+1 617 555 1212 +TEL;type=WORK:+1 (617) 555-1234 +TEL;type=CELL:+1 781 555 1212 +TEL;type=HOME:+1 202 555 1212 +item1.ADR;type=WORK:;;2 Enterprise Avenue;Worktown;NY;01111;USA +item1.X-ABADR:us +item2.ADR;type=HOME;type=pref:;;3 Acacia Avenue;Hoemtown;MA;02222;USA +item2.X-ABADR:us +NOTE:John Doe has a long and varied history\, being documented on more police files that anyone else. Reports of his death are alas numerous. +item3.URL;type=pref:http\://www.example/com/doe +item3.X-ABLabel:_$!!$_ +item4.URL:http\://www.example.com/Joe/foaf.df +item4.X-ABLabel:FOAF +item5.X-ABRELATEDNAMES;type=pref:Jane Doe +item5.X-ABLabel:_$!!$_ +CATEGORIES:Work,Test group +X-ABUID:5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\:ABPerson +END:VCARD diff --git a/VCF to Excle/vfc-to-excle.py b/VCF to Excle/vfc-to-excle.py new file mode 100644 index 00000000..720cabee --- /dev/null +++ b/VCF to Excle/vfc-to-excle.py @@ -0,0 +1,62 @@ +import pandas as pd +import argparse + + +def parse_vcf(vcf_file): + contacts = [] + + with open(vcf_file, 'r', encoding='utf-8') as file: + contact = {} + + for line in file: + line = line.strip() + + if line.startswith("BEGIN:VCARD"): + contact = {} + + elif line.startswith("FN:"): + contact["Full Name"] = line.replace("FN:", "") + + elif line.startswith("TEL"): + phone = line.split(":")[-1] + contact.setdefault("Phone Numbers", []).append(phone) + + elif line.startswith("EMAIL"): + email = line.split(":")[-1] + contact.setdefault("Emails", []).append(email) + + elif line.startswith("ORG:"): + contact["Organization"] = line.replace("ORG:", "") + + elif line.startswith("ADR"): + address = line.split(":")[-1].replace(";", " ") + contact["Address"] = address + + elif line.startswith("END:VCARD"): + contact["Phone Numbers"] = ", ".join(contact.get("Phone Numbers", [])) + contact["Emails"] = ", ".join(contact.get("Emails", [])) + contacts.append(contact) + + return contacts + + +def main(): + parser = argparse.ArgumentParser(description="Convert VCF to Excel") + parser.add_argument("input", help="Input VCF file") + parser.add_argument("-o", "--output", help="Output Excel file") + + args = parser.parse_args() + + input_file = args.input + output_file = args.output if args.output else input_file.replace(".vcf", ".xlsx") + + contacts = parse_vcf(input_file) + df = pd.DataFrame(contacts) + df.to_excel(output_file, index=False) + + print(f"✅ Conversion complete! Saved as {output_file}") + + +if __name__ == "__main__": + main() + From f301d90965a5cb14ec6a6f45f90f24218cb84344 Mon Sep 17 00:00:00 2001 From: Shaun2006 <116490490+shaun2006@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:42:54 +0530 Subject: [PATCH 2/2] changed if else statment to switch & removed emojis from print strings --- VCF to Excle/vfc-to-excle.py | 59 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/VCF to Excle/vfc-to-excle.py b/VCF to Excle/vfc-to-excle.py index 720cabee..2dce7e1f 100644 --- a/VCF to Excle/vfc-to-excle.py +++ b/VCF to Excle/vfc-to-excle.py @@ -5,41 +5,57 @@ def parse_vcf(vcf_file): contacts = [] - with open(vcf_file, 'r', encoding='utf-8') as file: + with open(vcf_file, "r", encoding="utf-8") as file: contact = {} for line in file: line = line.strip() - if line.startswith("BEGIN:VCARD"): - contact = {} + if not line: + continue - elif line.startswith("FN:"): - contact["Full Name"] = line.replace("FN:", "") + parts = line.split(":", 1) + if len(parts) != 2: + continue - elif line.startswith("TEL"): - phone = line.split(":")[-1] - contact.setdefault("Phone Numbers", []).append(phone) + field, value = parts + field_name = field.split(";")[0] # remove metadata like TEL;TYPE=CELL - elif line.startswith("EMAIL"): - email = line.split(":")[-1] - contact.setdefault("Emails", []).append(email) + match field_name: + case "BEGIN": + contact = {} - elif line.startswith("ORG:"): - contact["Organization"] = line.replace("ORG:", "") + case "FN": + contact["Full Name"] = value - elif line.startswith("ADR"): - address = line.split(":")[-1].replace(";", " ") - contact["Address"] = address + case "TEL": + contact.setdefault("Phone Numbers", []).append(value) - elif line.startswith("END:VCARD"): - contact["Phone Numbers"] = ", ".join(contact.get("Phone Numbers", [])) - contact["Emails"] = ", ".join(contact.get("Emails", [])) - contacts.append(contact) + case "EMAIL": + contact.setdefault("Emails", []).append(value) + + case "ORG": + contact["Organization"] = value + + case "ADR": + contact["Address"] = value.replace(";", " ") + + case "END": + contact["Phone Numbers"] = ", ".join( + contact.get("Phone Numbers", []) + ) + contact["Emails"] = ", ".join( + contact.get("Emails", []) + ) + contacts.append(contact) + + case _: + pass return contacts + def main(): parser = argparse.ArgumentParser(description="Convert VCF to Excel") parser.add_argument("input", help="Input VCF file") @@ -54,9 +70,10 @@ def main(): df = pd.DataFrame(contacts) df.to_excel(output_file, index=False) - print(f"✅ Conversion complete! Saved as {output_file}") + print(f"Conversion complete! Saved as {output_file}") if __name__ == "__main__": main() +