Skip to main content
 首页 » 编程设计

python之如何从python中的excel表中读取数据

2024年09月07日7cyq1162

selenium python框架中是否有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; 

打印(表格)

请您参考如下方法:

尝试 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)