0

I am getting this message when writing to an excel file using xlwt:

row index (u'RN') not an int in range(65536)

The line throwing the error come from here:

sheet.write(x,fieldKey, row.OBJECTID)

Where x is a counter I set to set the row value and fieldKey is another counter to set the column value.

I don't know why I am getting this message because the value (u'RN') is a string value, but it's telling me that it is not an int in range(65536). I believe the range(65536) is the limit of the excel table. Again, I was only writing 18 records, so I don't see why this error came up. Can anyone help?

Thanks, Mike

Mike
  • 4,099
  • 17
  • 61
  • 83
  • 1
    As you say the value is a *string* `rn` which is **not an int** - nevermind the range part... – Jon Clements Jul 12 '13 at 22:28
  • Why are you passing `u'RN'` as a column index/coordinate? What do you expect that to do? – abarnert Jul 12 '13 at 22:37
  • Ahhhh...I've been working on this for hours. I just found that I set x as a variable buried deep in my script in another instance. I actually tried looking for that earlier, but it just hit me now. Jon, your post made me look again. thanks for that. – Mike Jul 12 '13 at 22:39

4 Answers4

4

This is because you can not write to excel for more than 65536 lines. (You can now in the xlsx format). I had the same issue, try .to_csv()

1

According to this SO post the args to sheet.write should be ycoord,xcoord,value

so it should be something like sheet.write(0,0,answer1)

edited based on responses.

Community
  • 1
  • 1
NolanPower
  • 409
  • 3
  • 11
  • It's easier to remember if you call them row and col instead of y and x. Then the order seems natural, instead of backward. – abarnert Jul 12 '13 at 22:39
1

The error you are getting is because x (the row index) isn't a number, but a string. Check the values you are passing to the sheet.write method; the first two must be numbers (try printing them before making the call).

Racso
  • 2,310
  • 1
  • 18
  • 23
  • Well, maybe not _clearly_, but it seems likely that if you have a counter named `x` and a key named `fieldKey`, it's the latter that would hold a string `u'RN'`. But you're right, I'm making an assumption that could be wrong. – abarnert Jul 12 '13 at 22:41
  • Indeed: http://stackoverflow.com/questions/17624942/python-error-row-index-not-an-int-in-range65536/17625067#comment25659474_17624942 – Racso Jul 12 '13 at 22:41
  • Thanks everyone. I had through I was passing x as a number until it was overwritten with another x variable I had set. Thanks for all your help! – Mike Jul 15 '13 at 15:19
0

you can change in row.py inside the def init(self, rowx, parent_sheet) the limit, let's make it x2 for example:

if not (isinstance(rowx, int) and 0 <= rowx <= 131071):

changed from

if not (isinstance(rowx, int) and 0 <= rowx <= 65536):
kleopatra
  • 51,061
  • 28
  • 99
  • 211