This repository contains a Python script for formatting phone numbers with country codes. It processes non-standard phone numbers from Google Sheets, formats them correctly, and allows you to paste the results back into your Google Sheets for consistent formatting.
The script addresses the issue where phone numbers entered in a spreadsheet are not in a standard format. Common issues include missing country codes, inconsistent international prefixes, or non-numeric characters. This script helps in standardizing phone numbers by adding the correct international dialing codes.
To use the phone number formatting script, follow these steps:
- Python 3.x installed on your system.
- An IDE or text editor for running Python scripts (e.g., VSCode, PyCharm, Vim).
-
Clone the Repository:
git clone https://github.com/grbade/phone_number_formatter.git cd phone_number_formatter
-
Install Required Libraries:
The script uses the
re
library, which is included in Python's standard library, so no additional installations are required for dependencies.
Follow these steps to format phone numbers using the script:
- Copy Phone Numbers and Countries from Google Sheets:
- Open your existing Google Sheet that contains the phone numbers and countries.
- Copy the entire column of phone numbers.
- Copy the corresponding column of country names.
-
Paste the Data into the Script:
- Open the
phone_number_formatting.py
file in your text editor. - Replace the
phone_numbers
andcountries
lists in the script with the copied data.
Example:
# List of phone numbers from the input sheet phone_numbers = """355699823345 614323322342 43660112355""".split('\n') # List of countries corresponding to the phone numbers from the input sheet countries = """Albania Australia Austria""".split('\n')
- Open the
-
Run the Script:
Open a terminal and navigate to the directory containing the script. Run the script with:
python3 format_phone_numbers.py
-
Copy the Results:
- The script will output the formatted phone numbers in the terminal.
-
Open Your Google Sheet:
- Go to the Google Sheet where you want to paste the formatted phone numbers.
-
Paste the Formatted Numbers:
- Copy the output from the terminal and paste it into the appropriate column in your Google Sheet.
To ensure that phone numbers are displayed correctly:
-
Select the Column with Formatted Phone Numbers:
- Click on the column header.
-
Apply Custom Number Formatting:
- Go to
Format
>Number
>More Formats
>Custom number format
. - Enter the format
"+"0
and clickApply
.
- Go to
This format will display the phone numbers with a +
sign and the correct number of digits.
Input Data:
Phone Number | Country |
---|---|
00355699823345 | Albania |
4323322342 | Australia |
043660112355 | Austria |
Output Data:
Formatted Phone Number |
---|
+355699823345 |
+614323322342 |
+434660112355 |
- Error Handling: Ensure that the country names are spelled correctly and match the entries in the
country_to_code
dictionary in the script. - Formatting Issues: Verify that custom number formatting is correctly applied in Google Sheets.
Feel free to fork the repository and submit pull requests if you have improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.