openpyxl处理Excel——(行数、列数)

参考资料:

https://www.testwo.com/blog/7269

#导入openpyxl
from openpyxl import load_workbook

#创建文件路径
path=r"E:"
filename=“test.xlsx”
filepath=path+filename

#打开excel
xl=load_workbook(filepath)
#获取所有sheet页名字
xl_sheet_names=xl.get_sheet_names()
#打印所有sheet页名称
print(xl_sheet_names)

#定位到相应sheet页,[0]为sheet页索引
xl_sheet=xl.get_sheet_by_name(xl_sheet_names[0])

#获取行列数
row=xl_sheet.max_row
column=xl_sheet.max_column

#获取单元格值
xl_cell=xl_sheet.cell(row=i,column=j).value

#单元格赋值
xl_cell=xl_sheet.cell(row=i,column=j,value=“金额”)

#保存excel
xl.save(filepath)
原文地址:https://www.cnblogs.com/kearney908/p/7467590.html