Python:xlsxファイルを読み込む(Excel操作1)
1173 ワード
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:
@contact: [email protected]
@software: PyCharm
@file: 1 xlsx .py
@time: 2018/9/13 16:59
"""
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\ \AppData\Local\Programs\Python\Python36\Scripts\test\ - \ \Excel \1.xlsx"))