zoukankan      html  css  js  c++  java
  • 读取excel表格.py

    import xlrd

    #打开文件并拿到book对象:
    book = xlrd.open_workbook(r"D:s27day68接口测试示例.xlsx")
    sheet = book.sheet_by_index(0)
    print(sheet)

    #获取行:
    # print(sheet.nrows)

    #获取列:
    # print(sheet.ncols)

    #获取每行的内容:
    # for row in range(sheet.nrows):
    # print(sheet.row_values(row))

    #获取每列的内容:
    # for col in range(sheet.ncols):
    # print(sheet.col_values(col))

    #获取指定行内容:
    # print(sheet.row_values(1))

    #获取title:
    title = sheet.row_values(0)
    # print(title)

    l = []
    #获取其他行:
    for row in range(1,sheet.nrows):
    # print(sheet.row_values(row))
    l.append(dict(zip(title,sheet.row_values(row))))
    print(l)

    结果:[{'case_project': 'cnodejs项目', 'case_description': 'get /topics 主题首页', 'case_url': 'https://cnodejs.org/api/v1/topics', 'case_method': 'get', 'case_params': '', 'case_expect': '{"success":true}'}, {'case_project': 'cnodejs项目', 'case_description': 'get /topic/:id 主题详情', 'case_url': 'https://cnodejs.org/api/v1/topic/5433d5e4e737cbe96dcef312', 'case_method': 'get', 'case_params': '', 'case_expect': '{"success":true}'}, {'case_project': 'cnodejs项目', 'case_description': '/topic_collect/collect 收藏主题', 'case_url': 'https://cnodejs.org/api/v1/topic_collect/collect', 'case_method': 'post', 'case_params': '', 'case_expect': '{"success": false}'}, {'case_project': 'cnodejs项目', 'case_description': 'post /topic_collect/de_collect 取消主题', 'case_url': 'https://cnodejs.org/api/v1//topic_collect/de_collect', 'case_method': 'post', 'case_params': '', 'case_expect': '{"success": false}'}, {'case_project': 'cnodejs项目', 'case_description': '/user/:loginname 用户详情', 'case_url': 'https://cnodejs.org/api/v1/user/alsotang', 'case_method': 'get', 'case_params': '', 'case_expect': '{"success":true}'}, {'case_project': 'cnodejs项目', 'case_description': '/message/mark_all 标记全部已读', 'case_url': 'https://cnodejs.org/api/v1/message/mark_all', 'case_method': 'post', 'case_params': '', 'case_expect': '{"success": false}'}, {'case_project': 'v2EX项目', 'case_description': '获取网站信息', 'case_url': 'https://www.v2ex.com/api/site/info.json', 'case_method': 'get', 'case_params': '', 'case_expect': '{"title":"V2EX"}'}]


  • 相关阅读:
    计划给予心脏公式
    平原绫香 Hirahara Ayaka-Jupiter
    legend---十一、thinkphp事务中if($ans1&&$ans2){}else{}方式和try{}catch{}方式事务操作的区别在哪里
    chrome控制台常用技巧有哪些
    js中console强大之处体现在哪
    Pocket英语语法---五、形式主语是怎么回事
    智课雅思词汇---十二、vent是什么意思
    英语影视台词---八、the shawshank redemption
    Pocket英语语法---四、should的同义词是谁
    m_Orchestrate learning system---二十七、修改时如何快速找到作用位置
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12227396.html
Copyright © 2011-2022 走看看