I already referred these pposts here - here, here and here. Please don't mark it as duplicate
am trying to do some operations in my excel and finally save and protect them using a password. My openpyxl version is 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, user can only open with a password