Unlocking all cells in a column

50 views
Skip to first unread message

Roman Golovin

unread,
Dec 8, 2025, 5:12:37 AMDec 8
to openpyxl-users
Hi,

I looked in many sources. Currently there is no way to unlock all cells in a column. Is it possible to add this functionality to openpyxl? 

Unlocking cell by cell is time and memory consuming. In Excel it's possible to do it without performance loss.


Thank you,
Roman

Roman Golovin

unread,
Dec 8, 2025, 5:16:42 AMDec 8
to openpyxl-users
I need it to enable user to delete unlocked column (for protected sheet with enabled delete columns property). Now  user cannot delete a column where only cells with data are unlocked - It needs all column to be unlocked for such operation.

понедельник, 8 декабря 2025 г. в 11:12:37 UTC+1, Roman Golovin:

Charlie Clark

unread,
Dec 10, 2025, 1:02:28 PM (12 days ago) Dec 10
to openpyxl-users
On 8 Dec 2025, at 11:12, Roman Golovin wrote:

> Hi,
>
> I looked in many sources. Currently there is no way to unlock all cells in
> a column. Is it possible to add this functionality to openpyxl?

I think it already exists in the SheetProtection option:

https://openpyxl.pages.heptapod.net/openpyxl/api/openpyxl.worksheet.protection.html#openpyxl.worksheet.protection.SheetProtection.deleteColumns

> Unlocking cell by cell is time and memory consuming. In Excel it's possible
> to do it without performance loss.

It's always useful to include any relevant code that you've tried.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226

Roman Golovin

unread,
Dec 11, 2025, 9:57:22 AM (11 days ago) Dec 11
to openpyxl-users
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)
======================


I'd like having something like this:

======================
range = sheet['D':'F']
range .protection = Protection(locked=False)
======================

среда, 10 декабря 2025 г. в 19:02:28 UTC+1, charli...@clark-consulting.eu:

Charlie Clark

unread,
Dec 11, 2025, 12:22:25 PM (11 days ago) Dec 11
to openpyxl-users

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.

Reply all
Reply to author
Forward
0 new messages