import xlrd, base64
excel_obj = xlrd.open_workbook(file_contents=base64.decodestring(filename))。#打开要解析的excel
sheets = excel_obj.sheets() #读取sheet表内容
for sh in sheets:
for row in range(1, sh.nrows):
row_n = row + 1
name = sh.cell(row, 0).value #第一列的数据
size = sh.cell(row, 1).value #第二列的数据
material = sh.cell(row, 2).value #第三列的数据
#python读取excel中单元格的内容返回的有5种类型,即上面例子中的ctype:
# ctype: 0: empty, 1:string, 2:number, 3:date, 4:boolean, 5 :error
ctype = sheet.cell(i, j).ctype # 表格的数据类型
cell = sheet.cell_value(i, j)
if ctype == 2 and cell % 1 == 0: # 如果是整形
cell = int(cell)
elif ctype == 3:
# 转成datetime对象
date = datetime(*xldate_as_tuple(cell, 0))
cell = date.strftime(‘%Y/%d/%m %H:%M:%S‘)
elif ctype == 4:
cell = True if cell == 1 else False
更对内容参考:https://www.cnblogs.com/xxiong1031/p/7069006.html
原文:https://www.cnblogs.com/1314520xh/p/12589122.html