Search code examples
pythonxlw

python xlwt, write to the next available line


I know you can do this

sheet1.write(3, 3, 'TEXT')

Or you can do a for loop, but I have multiple users working with my file and I don't know what's the number of the current row.

I could create a var CurrentRow and increase it every time new user joins, but this might happen:

User1 is writing to the file (CurrentRow = 1)

User2 starts wrirting to the file (CurrentRow = 2)

So User1's data will be written in row #2.

Is there anything like

sheet1.write('next available line')?

Solution

  • No, there isn't some things like 'next available line', just because there isn't 'available line'. Writing is carried by cells and all the cells are available. You should exactly indicate number of cell when use write method.

    https://xlwt.readthedocs.io/en/latest/api.html#xlwt.Worksheet.Worksheet.write

    So you should not allow multiple access to the file in one time. It's absolutely not safe, not only for this case. The best way it's use some synchronizing means like locks or semaphores. I will be able to say more, if you take more details about your application architecture