I want to output the results of a Python script to the next available column (one without any data in it) of a specified row in an excel spreadsheet (XLS). Below is the portion of my code to do that:
The results I get are below:
True
True
True
True
True
True
True
True
True
Traceback (most recent call last):
File "/Users/myname/Desktop/TEST_Subnet_Pin g.py", line 48, in <module>
cell = sheet.cell(1,co l_test)
File "/Library/Frameworks/Python.framewor k/Versions/2.6/lib/python2.6/site-packages/xlrd/sheet.py", line 255, in cell
self._cell_type s[rowx][colx],
IndexError: array index out of range
It is correctly starting at column 1, checking to see if theres data there and if so it moves to the next column of that row and checks. When it gets to column 10, a column without any data, I get the IndexError. What I want is the cul_test number so that I can tell my script to output the results in whatever column number cul_test is. How can I set this up so that it doesn't give me any errors when it gets to a column that has absolutely no data in it at all? My expectation was that the WHILE would quit after finding a column with no data and I would have that cul_test number. I am not a programmer so this is all pretty new to me. It's probably something simple but I can not figure out what. Any help would be greatly appreciated and if you need more info please let me know. Thanks!
Code:
col_test = 1 col_num = open_workbook(subnet) sheet = col_num.sheet_by_index(0) cell = sheet.cell(1,col_test) cell.ctype == XL_CELL_TEXT while cell.ctype == True: col_test = col_test + 1 cell = sheet.cell(1,col_test) print cell.ctype == XL_CELL_TEXT column = cul_test
The results I get are below:
True
True
True
True
True
True
True
True
True
Traceback (most recent call last):
File "/Users/myname/Desktop/TEST_Subnet_Pin g.py", line 48, in <module>
cell = sheet.cell(1,co l_test)
File "/Library/Frameworks/Python.framewor k/Versions/2.6/lib/python2.6/site-packages/xlrd/sheet.py", line 255, in cell
self._cell_type s[rowx][colx],
IndexError: array index out of range
It is correctly starting at column 1, checking to see if theres data there and if so it moves to the next column of that row and checks. When it gets to column 10, a column without any data, I get the IndexError. What I want is the cul_test number so that I can tell my script to output the results in whatever column number cul_test is. How can I set this up so that it doesn't give me any errors when it gets to a column that has absolutely no data in it at all? My expectation was that the WHILE would quit after finding a column with no data and I would have that cul_test number. I am not a programmer so this is all pretty new to me. It's probably something simple but I can not figure out what. Any help would be greatly appreciated and if you need more info please let me know. Thanks!
Comment