Created
June 18, 2012 16:33
-
-
Save de1o/2949275 to your computer and use it in GitHub Desktop.
combination_of_each_2_item_in_a_row_of_xls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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