前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 通过xlrd库读取excel

python 通过xlrd库读取excel

作者头像
葫芦
发布2019-05-14 16:46:17
5640
发布2019-05-14 16:46:17
举报
文章被收录于专栏:葫芦葫芦

python通过xlrd库读取excel一例

代码语言:javascript
复制
#!/usr/bin/env python
# coding=utf-8
# author: wz
# mail: 277215243@qq.com
# datetime:2017/5/3 6:32 PM
# web: https://www.bthlt.com
import xlrd


def open_zones():
    open_zone_xls = xlrd.open_workbook("./openzone.xlsx")
    sheet = open_zone_xls.sheet_by_index(0)
    zone_id_index = 0
    zone_id_ip = 1
    zone_name_index = 2
    zone_attr_buf = 3
    zone_ip = 4
    zone_plat_index = 5
    zone_connect_url = 6
    zone_rs_ip_list = 7
    rows = sheet.nrows
    excel_list = list()
    for row in xrange(1, rows):
        row_dic = dict()
        row_dic['zone_id'] = int(sheet.cell_value(rowx=row, colx=zone_id_index))
        row_dic['zone_name'] = str(sheet.cell_value(rowx=row, colx=zone_name_index).encode("utf-8")).strip()
        row_dic['zone_plat'] = str(int(sheet.cell_value(rowx=row, colx=zone_plat_index))).strip()
        row_dic['zone_id_ip'] = str(sheet.cell_value(rowx=row, colx=zone_id_ip)).strip()
        row_dic['zone_attr_buf'] = str(sheet.cell_value(rowx=row, colx=zone_attr_buf)).strip()
        row_dic['zone_rs_ip_list'] = str(sheet.cell_value(rowx=row, colx=zone_rs_ip_list)).strip()
        row_dic['zone_ip'] = str(sheet.cell_value(rowx=row, colx=zone_ip)).strip()
        row_dic['zone_url'] = str(sheet.cell_value(rowx=row, colx=zone_connect_url)).strip()
        excel_list.append(row_dic)
    return excel_list


if __name__ == "__main__":
    print open_zones()
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/05/03 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • python通过xlrd库读取excel一例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档