from openpyxl.reader.excel import load_workbook
def readXlsx(path):
# 打开文件
file = load_workbook(filename=path)
# file.sheetnames获取所有工作表的名称
sheets = file.sheetnames
# print(sheets)
# 拿出一个表格file[sheets[0]] file[sheetname]
# sheet = file[sheets[0]]
# sheet.max_row 行数
# sheet.max_column 列数
# sheet.title 表名称
sheetsDic = {}
for sheetName in sheets:
sheet = file[sheetName]
sheetList = []
for lineNum in range(1, sheet.max_row + 1):
lineList = []
for columnNum in range(1, sheet.max_column + 1):
value = sheet.cell(row=lineNum, column=columnNum).value
lineList.append(value)
sheetList.append(lineList)
sheetsDic[sheetName] = sheetList
return sheetsDic
if __name__ == "__main__":
print(readXlsx(r"C:\Users\刘傲\Desktop\data.xlsx"))
py读取xlsx文件
最新推荐文章于 2024-09-07 01:00:00 发布