使用xlrd读取excel文件,支持.xls和.xlsx格式
from xlrd import *
path='test.xlsx'
wb = open_workbook( path )
sheet0 = wb.sheet_by_name('测试')
sheet1 = wb.sheet_by_index(1)
print(wb.sheet_names())
print(sheet0.name)
print(sheet1.name)
print(sheet0.ncols)
print(sheet0.nrows)
c1 = sheet0.cell(10,10)
print(c1)
print(c1.ctype)
row = sheet0.row(10)
print(row)
col = sheet0.col(6)
print(col)
data0 = sheet0.col_values(6,start_rowx=2,end_rowx=7)
print(data0)
data1 = sheet0.row_values(3,start_colx=2,end_colx=7)
print(data1)
for r in range(sheet0.nrows):
for c in range(sheet0.ncols):
print('%s' % sheet0.cell(r,c).value)
==========================
如果打开.xlsx格式的文件并要保留单元格的格式
xlrd.open_workbook(filePath,formatting_info=True,on_demand=True) ,会报错的,xlrd对.xlsx支持不是太好