首页 > 编程语言 > 详细

python解析excel

时间:2020-03-28 20:59:03      阅读:83      评论:0      收藏:0      [点我收藏+]
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

python解析excel

原文:https://www.cnblogs.com/1314520xh/p/12589122.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!