xyzio

Going through a xlsx spreadsheet by column in Python

leave a comment »

Most examples iterate by row. This one iterates by col.

import xlrd

workbook = xlrd.open_workbook('test_file.xlsx')
worksheet = workbook.sheet_by_index(0)

num_cols = worksheet.ncols - 1
curr_col = -1
while curr_col < num_cols:
    #Iterate through cols
    curr_col += 1
    col = worksheet.col(curr_col)
    for cell in col:
        #Iterate through cells in col
        print cell.value

Written by M Kapoor

September 25, 2014 at 3:29 pm

Posted in python

Leave a comment