simply I have 2 columns in excel file. lets say A and B after reading the excel file I want to store the values in dictionary like this: {A1:B1, A2:B2,.....} until the end of columns contents. How can I do that. thanks in advance.
I wrote demo code as below, hope is helps.
import openpyxl
workbook = openpyxl.load_workbook('./test.xlsx')
worksheet = workbook.active
dictionary = {}
for row in range(1, worksheet.max_row + 1):
key = worksheet.cell(row, 1).value
value = worksheet.cell(row, 2).value
dictionary[key] = value
print(dictionary)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.