【问题标题】:How to read data from excel sheet in python?如何从python中的excel表中读取数据?
【发布时间】:2018-09-03 12:20:54
【问题描述】:

有没有python脚本可以从selenium python框架中的excel表中读取数据?

我已经写了下面的代码,但我认为它不完全正确

def getcell(rows,cols):

table=list()
record=list()

for x in range(rows):
    for y in range(cols):
        record.append(SheetName.cell(x,y).value)    
        table.append(record)
        record=[]
        rows=rows+1

return table;

打印(表格)

【问题讨论】:

  • 我认为这个问题与 Selenium 没有任何关系(它可能只是与测试自动化间接相关)。请相应地编辑问题和标签。谢谢。
  • 你尝试过熊猫吗?处理您的问题似乎很自然?

标签: python selenium read-data


【解决方案1】:

试试xrld。用于读取 ms excel 表的 python 模块。这是其自述文件中提供的一个简单示例

import xlrd
book = xlrd.open_workbook("myfile.xls")
print "The number of worksheets is", book.nsheets
print "Worksheet name(s):", book.sheet_names()
sh = book.sheet_by_index(0)
print sh.name, sh.nrows, sh.ncols
print "Cell D30 is", sh.cell_value(rowx=29, colx=3)
for rx in range(sh.nrows):
    print sh.row(rx)

【讨论】:

  • 嗨 And3r50n 1,它有效。我有一个疑问,我们是否可以在有 excel 表的地方编写代码,并且我们必须使用 tc id's 读取多行。例如:我必须通过传递参数 tc01 来读取 1 行。
  • 是的,它会的。继续并将模块嵌入到程序中。如果它解决了您的问题,请接受答案并投票
  • 所以你能帮我用 tc id 的脚本写读取多行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-13
  • 2016-03-04
  • 2015-03-22
  • 1970-01-01
相关资源
最近更新 更多