2

是否有任何 python 脚本可以从 selenium python 框架中的 excel 表中读取数据?

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

def getcell(行,列):

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;

打印(表)

4

1 回答 1

3

试试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)
于 2018-03-25T06:28:44.837 回答