[英]how can I make a python dictionary from excel file using openpyxl?
simply I have 2 columns in excel file.只是我在 excel 文件中有 2 列。 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.
让我们在阅读 excel 文件后说 A 和 B 我想将值存储在字典中,如下所示:{A1:B1, A2:B2,.....} 直到列内容的末尾。 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.