简体   繁体   English

如何使用 openpyxl 从 excel 文件制作 python 字典?

[英]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.

相关问题 如何使用 openpyxl 从字典创建 Excel 文件扩展名 .xlsx? - How to create an Excel file extension .xlsx from a dictionary using openpyxl? 如何使用 openpyxl 将 csv 文件写入 Excel 工作表? - How can i write a csv file to an excel sheet using openpyxl? 如何使用 openpyxl 库将列从一张 excel 表复制到另一张 python? - How can I copy columns from one excel sheet to another with python using openpyxl Library? 如何使此python(使用openpyxl)程序运行更快? - How can I make this python(using openpyxl) program run faster? 使用 openpyxl 从字典中获取数据并将其放入 Excel 文件中 - Taking data from a dictionary and putting it into an Excel file using openpyxl 如何从 python 中的 txt 文件制作字典 - How can i make a dictionary from txt file in python 使用 openpyxl 从 excel 文件创建字典 - Creating a dictionary from excel file with openpyxl 如何从 python 文件中访问字典(使用 python) - How can i access a dictionary from a python file (using python) Python - 有没有办法可以使用 Openpyxl 动态播放 Excel 文件中的数据 - Python - Is there a way I can dynamically play with data in Excel file using Openpyxl 如何使用 Openpyxl Python 将转换后的文件保存到新的 excel 文件中? - How to save transformed file into new excel file using Openpyxl Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM