Skip to content

didinj/python-excel-google-sheet-automation-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Automate Excel and Google Sheets Tasks with Python

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.

πŸš€ Features

  • Read and write Excel files using pandas and openpyxl
  • Style Excel headers
  • Authenticate with Google Sheets using a service account
  • Upload and update Google Sheets with gspread and gspread_dataframe
  • Error handling and logging with logging
  • Modular Python code for easy reuse

πŸ“¦ Requirements

  • Python 3.7+
  • pandas
  • openpyxl
  • gspread
  • gspread_dataframe
  • oauth2client

Install dependencies:

pip install pandas openpyxl gspread gspread_dataframe oauth2client

πŸ” Google Sheets API Setup

  1. Go to Google Cloud Console
  2. Create a project and enable the Google Sheets API
  3. Create a Service Account, generate a key in JSON format, and download it as credentials.json
  4. Share your target Google Sheet with the service account email

πŸ“‚ Project Structure

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

πŸ§ͺ How to Use

  1. Place your credentials.json in the project directory
  2. Run the script:
python main.py
  1. Check the generated Excel file and your Google Sheet titled "Students Report"

πŸ›  Customize

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 cron or Windows Task Scheduler

🧾 License

MIT


Tutorial by Djamware.com - Automate Excel and Google Sheets Tasks with Python: Practical Examples