读取xls文件

openpyxl不能读xls, 只能读xlsx文件

  1. import xlrd
  2. infile = 'test.xls'
  3. wb = xlrd.open_workbook(infile)
  4. ws = wb.sheet_by_index(0)
  5. title_values = ws.row_values(0)
  6. for i in range(ws.nrows):
  7. row = ws.row_values(i)
  8. if i == 0:
  9. title = row
  10. continue
  11. context = dict(zip(title, row))
  12. print(context)