其他分享
首页 > 其他分享> > 用openpyxl读取excel文件(已封装)

用openpyxl读取excel文件(已封装)

作者:互联网

import openpyxl

def readExcel(path_name):
    myxl = openpyxl.load_workbook(path_name)#加载一个excel文件
    myexcel = myxl.active#获取活跃的excel
    col = myexcel.max_column#获取最大列数
    #print(col)
    row = myexcel.max_row#获取最大行数
    #print(row)
    for i in range(1,row+1):
        print('')
        for j in range (1,col+1):
            mycell = myexcel.cell(i,j)#获取表格小空间
            print(str(mycell.value)+'  ',end='')

标签:封装,openpyxl,myexcel,excel,print,col,row
来源: https://blog.csdn.net/yangyang0826/article/details/121719371