我的 excel 文件中有一个列,我想将该列的所有行转换为特定的字典格式。即双引号之间的keys和values以及括号和圆括号之间的values以及之前的单词设置,如图:
我使用此代码,但这并没有给我我想要的格式:
import openpyxl
# Access active worksheet of excel file
book = openpyxl.load_workbook('workbook.xlsx')
sheet = book.active
# Access first column
column = sheet['A']
# Use dictionary comprehension on the cells in the column
d = {
'item{}'.format(num): cell.value
for (num, cell) in enumerate(column, 1)
}
杨魅力
相关分类