Search code examples
pythonimport-from-excel

How to get information from an xlsx file in Python?


I have to create a mailing list of people belonging to a certain institution. The information is only available in .xlsx file. The columns of xlsx are as follows: institution, DOB, Program, ..., EmailID. How do I do this, instead of reading each entry myself and then typing the email into Google contacts?

I know I am asking a lot, especially since I have no idea how to operate Google sheets; like I am not sure if there is a way in Google sheets to do that. All I need are some directions.


Solution

  • You can read/write .xlsx files using openpyxl. Here is the link to the documentation.

    You can read from the .xlsx as follows:

    from openpyxl import load_workbook
    wb2 = load_workbook('email_contacts.xlsx')
    print wb2.get_sheet_names()
    

    To add the details into Google Contacts you can use the Google Contacts API. Just read the official documentation on how to use the API.