Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions VCF to Excle/README.md
Original file line number Diff line number Diff line change
@@ -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.

25 changes: 25 additions & 0 deletions VCF to Excle/sample.vcf
Original file line number Diff line number Diff line change
@@ -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:_$!<HomePage>!$_
item4.URL:http\://www.example.com/Joe/foaf.df
item4.X-ABLabel:FOAF
item5.X-ABRELATEDNAMES;type=pref:Jane Doe
item5.X-ABLabel:_$!<Friend>!$_
CATEGORIES:Work,Test group
X-ABUID:5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\:ABPerson
END:VCARD
79 changes: 79 additions & 0 deletions VCF to Excle/vfc-to-excle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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 not line:
continue

parts = line.split(":", 1)
if len(parts) != 2:
continue

field, value = parts
field_name = field.split(";")[0] # remove metadata like TEL;TYPE=CELL

match field_name:
case "BEGIN":
contact = {}

case "FN":
contact["Full Name"] = value

case "TEL":
contact.setdefault("Phone Numbers", []).append(value)

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")
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()