Я хочу защитить Excel паролем, который доступен в корзине S3, и сохранить его обратно в s3. Я пробовал с помощью openpyxl и xlsxwriter, он генерирует файл xlsx, но открывается без запроса пароля
import openpyxl
import shutil
def password_protect_excel(filename, password):
# Load the workbook from the mount location
workbook = openpyxl.load_workbook(filename)
# Placeholder for password protection
print(f"Attempting to set a password on the workbook: {password}")
# Save the workbook to a local temporary path first
temp_local_path = "/tmp/Report_temp.xlsx"
workbook.save(temp_local_path)
return temp_local_path
if __name__ == "__main__":
# Define the mount location paths
input_file = "/dbfs/mnt/file_mount_report/Report.xlsx"
output_file = "/dbfs/mnt/file_mount_report/Report_protected_new.xlsx"
# Password placeholder
password = "your_strong_password"
# Step 1: Process the Excel file
temp_local_path = password_protect_excel(input_file, password)
# Step 2: Move the saved file to the mount location
shutil.copy(temp_local_path, output_file)
print(f"Workbook saved at {output_file}")
Подробнее здесь: https://stackoverflow.com/questions/790 ... databricks