I'm dealing with cell locking (unlocking) using openpyxl module.
What I need to do is to set the locking property of all cells of a workbook. The openpyxl "standard" iterators are not going throught all the cells (only the ones that have values - not the whole workbook), and forcing that using the iter_rows() method is leading to time and memory issues.
Maybe defining a style and applying it to all the cellls could help?
Based on what I understood from openpyxl documentation, seems that this approach (modifying property or styles of a cell range in one shot) is not feasible... but maybe I missed something.
Or are there any different modules that I could use?
Any kind of help is really appreciated. Thanks.
BelleroDev
What I need to do is to set the locking property of all cells of a workbook. The openpyxl "standard" iterators are not going throught all the cells (only the ones that have values - not the whole workbook), and forcing that using the iter_rows() method is leading to time and memory issues.
import openpyxl
def reset_locking(file):
workbook = openpyxl.load_workbook(file)
# first implementation
for sheet in workbook:
for row in sheet.rows:
for cell in row:
cell.protection = openpyxl.styles.Protection(locked = True)
#second implementation
#max data are related to Exel version >= 2016
for sheet in workbook:
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=1048576, max_col=16384):
for cell in row:
cell.protection = openpyxl.styles.Protection(locked = True)Is there a different (or smarter) way to do it?Maybe defining a style and applying it to all the cellls could help?
Based on what I understood from openpyxl documentation, seems that this approach (modifying property or styles of a cell range in one shot) is not feasible... but maybe I missed something.
Or are there any different modules that I could use?
Any kind of help is really appreciated. Thanks.
BelleroDev
