大方式有两种;一种是按python给的接口,遍历cell
有两种方式,一种是一行一个list,最后一个list的list
一种是一列一个list,最后一个list的list
以列组list
import openpyxl
file="source.xlsx"
try:
workbook=openpyxl.load_workbook(file)
except:
print("An error occur on load_workbook")
sheet =workbook["Routing Table"]
list_all =[]#放所有数据的list
for column in sheet.columns:
cellnew=[]#列list
for cell in column:
cellnew.append(cell.value)
list_all.append(cellnew)
print(list_all)
以行组list
同理,只不过用的是sheet.rows
一种是按索引循环:
for rownum in range(0,sheet.max_row):
for colnum in range(0.sheet.max_column):
XXXXX