In Excel cells there is a locked attribute , which is enabled by default. However, this attribute is only called when the worksheet security attribute is also set to True. If the worksheet is not protected, the attribute locked is ignored.
Therefore, your question is not best framed by how to make read-only cells. Rather, the question is how to make cells editable after protecting the worksheet.
... Here you are:
from xlwt import Workbook, Worksheet, easyxf
my_worksheet.protect = True
my_worksheet.password = "something_difficult_to_guess"
editable = easyxf("protection: cell_locked false;")
read_only = easyxf("")
my_worksheet.write(0, 0, "Can't touch this!", read_only)
my_worksheet.write(2, 2, "Erase me :)", editable)
Cell styles easyxfare also useful for declaring background colors, font weights, etc.
Greetings.
source
share