1、安装
pip install openpyxl
2、打开工作簿
wb = openpyxl.load_workbook("./test.xlsx")
3、选择表单
sheet = wb["sheet1"]
4、获取指定单元格的数据
print(sheet.cell(1, 2).value)
5、获取单元格最大行数和列数
print(sheet.max_row)
print(sheet.max_column)
6、输出excel文件中的所有内容
# 方法一
m_row = sheet.max_row
m_column = sheet.max_column
for i in range(1, m_row + 1):
for j in range(1, m_column + 1):
print(sheet.cell(i, j).value, end="\t")
print()
# 方法二
m_data_list = list(sheet.values)
for i in range(len(m_data_list)):
for j in range(len(m_data_list[i])):
print(m_data_list[i][j], end="\t")
print()
注意:excel单元格下标是从1开始的
标签:sheet,openpyxl,python,excel,list,max,print,data,row From: https://blog.51cto.com/u_15694134/6079461