python Openpyxl模块常用方法

python Openpyxl模块常用方法

1.打开Excel:
wb =openpyxl.load_workbook(“apicases.xlsx”)
2.定位表单:
sheet = wb[“login”]
3.读取表单数据:
data=sheet.cell(3,7).value
4.获取最大行,最大列:
max_row = sheet.max_row
max_column= sheet.max_column
5.写入数据:
sheet.cell(10,10,“这是一个写入测试”)
wb.save(file)
6.遍历表格中所有数据:
datas = []
for i in range(1,max_row+1):
for j in range(1, max_column+1):
data = sheet.cell(i,j).value
datas.append(data)
print(datas)


分享到 :

Leave a Reply

Your email address will not be published. Required fields are marked *