美文网首页jmeter
python读取excel内容

python读取excel内容

作者: 小鱿鱼Gun神 | 来源:发表于2019-10-09 15:21 被阅读0次

读取excel的内容,xlrd(读),安装xlrd模块 pip install xlrd

首先,创建一个excel文档放在项目目录dataconfig文件夹下


excel文件.png

获取单元格内容

import xlrd

class OperationExcel:
    #构造函数
    def __init__(self,file_name=None,sheet_id=None):
        if file_name:
            self.file_name = file_name
            self.sheet_id = sheet_id
            self.data=self.get_data()
        else:
            self.file_name ='../dataconfig/interface.xlsx' #excel地址
            self.sheet_id = 0
        self.data = self.get_data()
    #获取sheet的内容
    def get_data(self):
        data = xlrd.open_workbook(self.file_name)
        tables = data.sheets()[self.sheet_id]
        return tables
    #获取单元格的行数
    def get_lins(self):
        tables=self.data
        return tables.nrows
    #获取某一单元格内容
    def get_cell_value(self,row,col):
        return self.data.cell_value(row,col)

if __name__=='__main__':
    opers = OperationExcel()
    #打印出单元格行数
    print(opers.get_data().nrows)
    #打印单元格行数
    print(opers.get_lins())
    #打印单元格内容
    print(opers.get_cell_value(1,2))
打印结果.png

相关文章

  • Xlrd Xlsxwrite Openpyxl

    1、python读取excel中单元格内容为日期的方式python读取excel中单元格的内容返回的有5种类型,即...

  • Excel读取并存入数据库通用处理【原创】

    此文为连载内容,Excel操作第二篇,对Excel的读取请参考Python对Excel读取 二、读取之后存入数据库...

  • python读取excel内容

    读取excel的内容,xlrd(读),安装xlrd模块 pip install xlrd 首先,创建一个excel...

  • python操作excel

    python操作excel 读取excel 写excel

  • Python导出excel数据【原创】

    此文为连载内容,Excel操作第三篇,对Excel的读取请参考Excel读取并存入数据库通用处理Python对Ex...

  • Python中Excel转化CSV【原创】

    此文为连载内容,Excel操作第四篇,对Excel的其他操作请参考Python导出excel数据Excel读取并存...

  • 2020-07-14

    今日目标--80%用python实现excel转置 要读取excel的内容以及行列数形成数组 从形成的数组中读取内...

  • Python实用-Excel批量合并

    需求:将多个Excel中的内容汇总合并成一个文件 涉及内容: 1.python扩展库:xlrd(读取Excel文件...

  • python读文件-20170905

    1.主要功能:(1)读取txt文件,(2)将文件内容存储到excel中 python读取文件时提示"Unicode...

  • python处理excel表格

    python中读取excel的包:xlrd python中写入excel的包:xlwt 原excel基础上添加列,...

网友评论

    本文标题:python读取excel内容

    本文链接:https://www.haomeiwen.com/subject/bdkgpctx.html