Python xlwt – 只读列(单元格保护)

有没有办法让一个特定的单元格只读/写在python xlwt保护?

我知道有一个cell_overwrite_ok标志不允许覆盖单元格(所有单元格)的内容,但可以逐个单元地完成。

谢谢,孙

Excel单元格具有默认启用的locking属性。 但是,只有在工作表保护属性也设置为True时,才会调用此属性。 如果工作表不受保护,则locking的属性将被忽略。

因此,你的问题并不是最好的框架, 如何使细胞只读 。 相反,问题是如何在保护工作表后使单元格可编辑

…这个给你:

 from xlwt import Workbook, Worksheet, easyxf # ... # Protect worksheet - all cells will be read-only by default my_worksheet.protect = True # defaults to False my_worksheet.password = "something_difficult_to_guess" # Create cell styles for both read-only and editable cells editable = easyxf("protection: cell_locked false;") read_only = easyxf("") # "cell_locked true" is default # Apply your new styles when writing cells my_worksheet.write(0, 0, "Can't touch this!", read_only) my_worksheet.write(2, 2, "Erase me :)", editable) # ... 

单元格样式( easyxf类)也可用于声明背景颜色,字体重量等。

干杯。