#打开excel文档
workbook = xlrd.open_workbook('..\cye.xls',encoding_override='utf-8') #获取sheet页信息
sheet = workbook.sheet_names()
print (sheet)
sheet1 = workbook.sheet_by_index(0)
sheet2 = workbook.sheet_by_name('TestData') print (sheet1.name)
print (sheet1.nrows)
print (sheet1.ncols) #获取一整行、列的值
print (sheet1.row_values(0))
print (sheet1.col_values(1)) #获取单元格的内容
print (sheet1.cell(0,1))
print (sheet1.cell_value(1,0).decode('utf-8').encode('utf-8'))
#利用decode解码,再用encode编码输出,就可以获取中文的单元格数据

#获取单元格内数据的类型
print (sheet1.cell(0,1).ctype)

输出结果见下:

[u'TestCase', u'TestData']
TestCase
3
2
[u'1row1col', u'1row2col']
[u'1row2col', u'1row2col', u'1row2col']
text:u'1row2col'
2row1col
1

05-21 05:47