1. python 读xlsx文件,获得列数据
from openpyxl import load_workbook
wb = load_workbook('../dao_chu_data/dao_chu_data.xlsx')
sheets = wb.worksheets # 获取当前所有的sheet
sheet1 = sheets[0] # 获取第一张sheet
# 通过Cell对象读取
rows = sheet1.rows #获取sheet页的行数据
i= 0
list_name = []
list_code = []
for row in rows: # 迭代所有的行
i = i + 1
line = [col.value for col in row]
cell_data_1 = sheet1.cell(row=i, column=1).value #获取第i行1列的数据
cell_data_2 = sheet1.cell(row=i, column=2).value #获取第i行2列的数据
list_name.append(cell_data_1)
list_code.append(cell_data_2)
list_name = list_name[1:]
list_code = list_code[1:]
print(list_name)
print(list_code)
本文介绍如何使用Python的openpyxl库从Excel (.xlsx) 文件中读取特定列的数据,并将其存储为列表形式,便于进一步的数据处理和分析。
2278

被折叠的 条评论
为什么被折叠?



