Python 使用xlrd读取Excel格式文件,pythonxlrd,[Python]代码im


[Python]代码

import xlrdfname = "sample.xls"bk = xlrd.open_workbook(fname)shxrange = range(bk.nsheets)try:    sh = bk.sheet_by_name("Sheet1")except:    print "no sheet in %s named Sheet1" % fname    return Nonenrows = sh.nrowsncols = sh.ncolsprint "nrows %d, ncols %d" % (nrows,ncols)cell_value = sh.cell_value(1,1)print cell_valuerow_list = []for i in range(1,nrows):    row_data = sh.row_values(i)    row_list.append(row_data)

评论关闭