37,720
社区成员
发帖
与我相关
我的任务
分享
import xlrd
class ExcelToData:
@staticmethod
def read_to_list(file: str) -> list:
"""
取出excel文件中的所有信息
:param file: excel文件名(带路径)
:return: 二维list,外层为sheet,内层为行,元素为单元格
"""
excel = xlrd.open_workbook(file)
result_list = []
for sheet in excel.sheets():
sheet_list = []
for row in range(sheet.nrows):
row_list = []
for cols in range(sheet.ncols):
row_list.append(sheet.cell(row, cols).value)
sheet_list.append(row_list)
result_list.append(sheet_list)
return result_list