From Excel, how can I parse 'Sheet1' and 'Sheet2' in to a list? I'm currently using xlrd, as shown in the code below.
Sheet1:
Sheet2:
My code:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import print_function
import xlrd
import sys
loc = 'excel.xlsx'
wb = xlrd.open_workbook(loc, encoding_override="iso-8859-5, cyrillic")
wb_name = wb.sheet_names()
count = len(wb_name)
data = []
column_excel =('Name', 'Course', 'Cost', 'level')
count_column = len(column_excel)
for i in range(count):
ow = xlrd.open_workbook('excel.xlsx').sheet_by_index(i)
for x in range (0, 100):
for i in range(2):
try:
if ow.cell_value(0, x) == column_excel[i]:
ips = ow.col_values(x, 1)
data.append(ips)
break
except IndexError:
continue
print(data)
My results:
[['Andre'], [1], [200], [5],
['Sam'], [2], [100], [8],
[7], ['Antony'], [4], [150],
[9], ['Ben'], [3], [500]]
Expected output:
[['Andre'], [1], [200], [5],
['Sam'], [2], [100], [8],
['Antony'], [4], [7], [150],
['Ben'], [3], [9], [500]]

