Home > Net >  Python script for writing an API key into excel
Python script for writing an API key into excel

Time:05-19

I need to take the API key u QBLoEyLWGS… (this is an arbitrary key) at the command prompt and insert it into a particular cell of an excel sheet. Any ideas regarding how to write a python script to achieve this would be appreciated. Thank you!

CodePudding user response:

You can use existing libraries such as Openpyxl, which supports all kinds of operations on Excel sheets. Install using

pip install openpyxl

If you want to take input from the command line, you can use the input keyword

API_key = input("What is the API key? \n")

Then use Openpyxl to add this into your cell on the excel sheet. Taken directly from the Openpyxl docs:

from openpyxl import Workbook
wb = Workbook()

# grab the active worksheet
ws = wb.active

# Data can be assigned directly to cells
ws['A1'] = API_key

# Save the file
wb.save("sample.xlsx")
  • Related