Skip to content

Instantly share code, notes, and snippets.

@de1o
Created June 18, 2012 16:33
Show Gist options
  • Save de1o/2949275 to your computer and use it in GitHub Desktop.
Save de1o/2949275 to your computer and use it in GitHub Desktop.
combination_of_each_2_item_in_a_row_of_xls
from xlrd import open_workbook
from xlwt import Workbook
book = open_workbook('test.xls')
sheet = book.sheet_by_index(0)
ready_to_write = []
def proc(l):
for i in range(l.__len__()):
for item_after_i in l[(i+1):]:
ready_to_write.append([l[i], item_after_i])
for row_num in range(sheet.nrows):
row = sheet.row(row_num)
not_empty_in_row = []
for cell in row:
if(cell.value):
not_empty_in_row.append(cell.value)
proc(not_empty_in_row)
print ready_to_write
wtbook = Workbook()
sheet1 = wtbook.add_sheet('Sheet 1')
for i in range(ready_to_write.__len__()):
sheet1.write(i, 0, ready_to_write[i][0])
sheet1.write(i, 1, ready_to_write[i][1])
wtbook.save('combination_result.xls')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment