python excel reading last empty cell -
i trying read till last empty cell specified number of rows.
here code:
for j in xrange(0,repeat_const,1): if r_sheet.cell_type(row+j,0)== xlrd.xl_cell_empty: break this code works if cell has been written earlier , deleted. not work if cell never been edited. not sure how handle this. please me this. grateful support.
regards, pavan
the error you're experiencing suggests rowx or colx arguments out of bounds for sheet.
in cell access functions, "rowx" row index, counting zero, , "colx" column index, counting zero. negative values row/column indexes , slice positions supported in expected fashion.
i found out (never used xlrd before) if query r_sheet.nrows bet you'll find value less row+j. appears xlrd reads part of worksheet, usedrange excel.
so can use exception handling, either try/catch block or this. note should short-circuit on first part of boolean expression whenever row+j greater nrows attribute of sheet.
if (row+j <= r_sheet.nrows-1) , (r_sheet.cell_value(row+j,0) = ''): break or, perhaps original method:
if (row+j <= r_sheet.nrows-1) , (r_sheet.cell_type(row+j,0)== xlrd.xl_cell_empty): break
Comments
Post a Comment