On 11 Dec 2025, at 15:57, Roman Golovin wrote:
Yes, sure
I do this cycle:
======================
for row in sheet.iter_rows(min_row=1, max_row=1048576, min_col=10,
max_col=30:
for cell in row:
cell.protection = Protection(locked=False)
But that isn't what you said… There are two problems with this approach. The first, as you know, is that you have to create all the cells in the range; the second is instantiating the Protection object. At least the second one can be simplified by only creating it once.
I'd like having something like this:
======================
range = sheet['D':'F']
range .protection = Protection(locked=False)
This isn't possible because there is nowhere in the OOXML specification to store this information: cell formatting is always at the cell level. However, what Excel does allow is to set the style for cells that have not yet been created in memory, styles also include protection information. In Openpyxl you can do this by creating a named style and assigning it to the relevant column dimension. I haven't looked at the details for this but it should be possible.
Be prepared to look at the source both for the worksheet and the styles.