lundi 30 mars 2015

what is the value of nrows of excel file in python xlrd

I'm new to programming world. I want to know the value of "sheet.nrows".


i'm writing the program for creating and feeding record in excel file. and somehow i manage to so by "try, error , modify" method, but i got stuck in understading the code i get from detecting blank cell in excel it work fine and doing its job of creating the serial no.


scenario 1:



book_r = xlrd.open_workbook("text.xls")
first_sheet = book_r.sheet_by_name("Form")
row_count = 1

for row_index in range(first_sheet.nrows):
value = first_sheet.cell(rowx=row_index, colx=0).value
if value != "Sr.No." or value != range(1, 200):
sheet1.write(row_index + 1, 0, row_count)
row_count += 1


it gives output in excel file like :



Sr.No.
1
2
3
4
5
6


scenario 2:



sheet1.write(row_index + 2, 0, row_count)


it gives output in excel file like



Sr.No.

1
2
3
4
5
6



with a blank after Sr.no.



i'm not getting why the gap arises after Sr.no. and as u increase the row value in sheet1.write(row_index + 1, 0, row_count) gap also increases


Aucun commentaire:

Enregistrer un commentaire