Advertisement
gregwa

XLRD - Example3.py

Mar 8th, 2015
504
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import xlrd
  2.  
  3. def OpenFile(path):
  4.     book = xlrd.open_workbook(path)
  5.     first_sheet = book.sheet_by_index(0)
  6.     # Get the number of rows in this workbook
  7.     rows = first_sheet.nrows
  8.     # get the number of columns in this workbook
  9.     cols = first_sheet.ncols
  10.     print "There are %d rows in this workbook." % rows
  11.     print "There are %d cols in this workbook." % cols
  12.     for r in range(0,rows):
  13.         cells = first_sheet.row_slice(rowx=r,start_colx=0,end_colx=cols)
  14.         for c in cells:
  15.             if c.ctype == xlrd.XL_CELL_DATE:
  16.                 date_value = xlrd.xldate_as_tuple(c.value,book.datemode)
  17.                 dt = str(date_value[1]) + "/" + str(date_value[2]) + "/" + str(date_value[0])
  18.                 print dt
  19.             else:
  20.                 print c.value
  21.        
  22.        
  23. if __name__ == "__main__":
  24.     path = "example1.xls"
  25.     OpenFile(path)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement