1

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')?
jack
  • 13
  • 3

1 Answers1

1

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

Silicon
  • 306
  • 3
  • 11
  • Thank you for your answer, well, it's basically a telegram bot that asks question and users have to answer them and every answer should be written in excel file. – jack Aug 20 '18 at 06:53
  • You can just create lock as global variable, if your application function-based. Or it can be static param, if app is class-based. Any way, you need to create lock (for example, you can take it from multiprocessing lib), accure it, when you write to file, and release, when writting is done. [https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Lock](https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Lock) Also you can create separate file for every user, but I don't sure that is clearly style and how it corresponds with your app's logic – Silicon Aug 21 '18 at 07:19