chronossc/openpyxl

Locked Cells...

Closed this issue · 0 comments

I have identified a bug; I coded around it. But before I say what it is, I just want to praise you for this incredibly strategic library for open source software. Many people do not get the point to your library; I see many people saying things on StackOverflow posts like: "getting that info is easy in pandas..." Your product allows you to get detailed info that pandas cannot AND generate data renditions in a format that most non-power end-users like for the purposes of analysis. And not just for Microsoft Office; but open source LibreOffice!

That said: I have a book with a tab where all cells except some header ones are saved with their "Locked" setting set to false. Upon opening that book and setting that tab to protected and saving to a file, all the cells in the last column would get locked; all the other cells were still unlocked, as to be expected.

Something I'm doing causing that? Well, IMMEDIATELY after I opened the book, I ran this function (column "H" happens to be the last column in my book...):

HEADER_ROW=1
# .
# .
# .
def check_protection(tab, label):
    'used to detect openpyxl bug; '+ \
    'last column is set as locked, even though cells were previously saved as unlocked...'
    global HEADER_ROW

    print ('PROTECTION: '+label)
    print (tab.cell(row=HEADER_ROW+1, column=8).protection.locked) # H2...

The cell in the last column would show as locked immediately after opening the book, even though I double checked it was not before I ran the code.

As a workaround for now, I determined the last column and set all the cells as unlocked before saving the book.

If there's any diagnostic info you need, let me know...