In [1]:
import xlrd
import pprint
In [2]:
wb = xlrd.open_workbook('data/src/sample.xlsx')
In [3]:
print(type(wb))
In [4]:
print(wb.sheet_names())
In [5]:
sheets = wb.sheets()
In [6]:
print(type(sheets))
In [7]:
print(type(sheets[0]))
In [8]:
sheet = wb.sheet_by_name('sheet1')
In [9]:
print(type(sheet))
In [10]:
cell = sheet.cell(1, 2)
In [11]:
print(cell)
In [12]:
print(type(cell))
In [13]:
print(cell.value)
In [14]:
print(sheet.cell_value(1, 2))
In [15]:
col = sheet.col(1)
In [16]:
print(col)
In [17]:
print(type(col[0]))
In [18]:
col_values = sheet.col_values(1)
print(col_values)
In [19]:
print(sheet.row_values(1))
In [20]:
pprint.pprint([sheet.row_values(x) for x in range(4)])
In [21]:
def get_list_2d(sheet, start_row, end_row, start_col, end_col):
return [sheet.row_values(row, start_col, end_col + 1) for row in range(start_row, end_row + 1)]
In [22]:
l_2d = get_list_2d(sheet, 2, 3, 1, 2)
print(l_2d)
In [23]:
print(sheet.nrows)
In [24]:
def get_list_2d_all(sheet):
return [sheet.row_values(row) for row in range(sheet.nrows)]
In [25]:
l_2d_all = get_list_2d_all(sheet)
pprint.pprint(l_2d_all)
In [26]:
print(l_2d_all[1][0])