【excel】Python实现excel转成列表

1.xlsx的内容,Python实现excel转成列表

A11 B1 C61
A12 B2 C62
A13 B3 C63
A14 B4 C64
from openpyxl import load_workbook

#实现excel转成二维列表
def excel_to_lists(filename,sheetname):
    wb = load_workbook(filename)
    ws = wb[sheetname]
    # 读取数据,比如把excel中的一个table按行读取出来,存入一个二维的list
    total_list = []
    for row in ws.rows:
        row_list = []
        for cell in row:
            row_list.append(cell.value)
        total_list.append(row_list)
    return total_list

list1=excel_to_lists('1.xlsx','Sheet1')

#通过遍历列表获取值
for i in list1:
    print(i[0])

你可能感兴趣的:(【excel】Python实现excel转成列表)