This project demonstrates how to automate tasks with Microsoft Excel and Google Sheets using Python. It includes practical examples for reading, writing, formatting, and syncing spreadsheet data, complete with error handling and logging.
Read the full tutorial here.
- Read and write Excel files using
pandasandopenpyxl - Style Excel headers
- Authenticate with Google Sheets using a service account
- Upload and update Google Sheets with
gspreadandgspread_dataframe - Error handling and logging with
logging - Modular Python code for easy reuse
- Python 3.7+
pandasopenpyxlgspreadgspread_dataframeoauth2client
Install dependencies:
pip install pandas openpyxl gspread gspread_dataframe oauth2client- Go to Google Cloud Console
- Create a project and enable the Google Sheets API
- Create a Service Account, generate a key in JSON format, and download it as
credentials.json - Share your target Google Sheet with the service account email
excel_google_automation/
βββ main.py # Main automation script
βββ credentials.json # Google API credentials (not included)
βββ automation.log # Generated log file
βββ students.xlsx # Example Excel file (generated)
βββ README.md # Project documentation
- Place your
credentials.jsonin the project directory - Run the script:
python main.py- Check the generated Excel file and your Google Sheet titled "Students Report"
You can modify the main() function in main.py to:
- Load data from a CSV or database
- Update different Google Sheets
- Schedule the script using
cronor Windows Task Scheduler
MIT
Tutorial by Djamware.com - Automate Excel and Google Sheets Tasks with Python: Practical Examples