I've already linked to these posts here - here, here, and here. Don't mark it as duplicate, please.
I'm attempting to use my excel to perform some procedures before saving and password-protecting them. I'm using openpyxl 3.0.9.
So, I tried the below
for search, v in merge_df.groupby(['Country']):
writer = pd.ExcelWriter(f"BC_{Country}.xlsx", engine='xlsxwriter')
v.to_excel(writer,columns=col_list,sheet_name=f'BC_{Country}',index=False, startrow = 1)
wb1 = load_workbook(filename = f"BC_{Country}.xlsx")
sheet_to = wb1.worksheets[0]
wb1.security.workbookPassword = "test"
wb1.save(f"BC_{Country}.xlsx")
But I get the below error:
AttributeError: 'NoneType' object has no attribute 'workbookPassword'
How can I protect my excel sheet with a password?
So, the user can only open it with a password.