Skip to content

Instantly share code, notes, and snippets.

@not-for-me
Created October 20, 2014 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save not-for-me/b2a80c1afcb3b8515c8b to your computer and use it in GitHub Desktop.
Save not-for-me/b2a80c1afcb3b8515c8b to your computer and use it in GitHub Desktop.
Python Program for reading xls
# coding: utf-8
from xlrd import open_workbook
wb = open_workbook('simple.xls')
for sheet in wb.sheets():
print(u'Sheet:' + sheet.name)
print("Number of Sheets: " + str(wb.nsheets))
for sheet_index in range(wb.nsheets):
sheet = wb.sheet_by_index(sheet_index)
print(u'Sheet Name: ' + sheet.name)
print(u'Sheet Rows: ' + str(sheet.nrows))
print(u'Sheet Cols: ' + str(sheet.ncols))
for row_index in range(sheet.nrows):
for col_index in range(sheet.ncols):
print("Type("+str(row_index)+","+str(col_index)+"): "+str(sheet.cell(row_index, col_index).ctype))
print("Value("+str(row_index)+","+str(col_index)+"): "+sheet.cell(row_index, col_index).value)
for row_index in range(sheet.nrows):
for col_index in range(sheet.ncols):
print(sheet.cell_value(row_index, col_index))
print(sheet.cell_type(row_index, col_index))
sheet_0 = wb.sheet_by_index(0)
row0_1 = sheet_0.row_slice(0,1)
print(row0_1[0])
print(row0_1[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment