栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 操作Excel(读取)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 操作Excel(读取)

# !/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:victor Li
import openpyxl

from common.dir_config import DirInfo
from common.elements import Element


class OpearteExcel:
    file_name = ""

    def __init__(self, file_name):
        self.file_name = file_name

    def get_book(self):
        wb = openpyxl.load_workbook(DirInfo.file_path.value + "test.xlsx")
        return wb

    def read_case(self):
        wb = self.get_book()
        ws = wb["测试用例集合"]
        case_list = []
        # 从第二行到最大行  并只遍历第二列
        for row in ws.iter_rows(min_row=2, max_row=ws.max_row, min_col=2, max_col=2):
            cell = [cell.value for cell in row]
            if cell[0] is None:
                break
            case_list.append(cell[0])
        return case_list
    def read_element(self):
        wb = self.get_book()
        ws = wb['测试元素库']
        for row in ws.iter_rows(min_row=2,max_row=ws.max_row,min_col=1):
            cell=[cell.value for  cell in row]
            if cell[0] is None:
                break
            Element.update({cell[0]:[cell[1],cell[2]]})
        print(Element)
   # def
if __name__ == '__main__':
    OpearteExcel("test.xlsx").read_element()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/864230.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号