安装 msoffcrypto-tool
使用pip命令安装: 打开命令行工具(如终端、命令提示符或Powershell),然后输入以下命令来安装msoffcrypto-tool:
pip install msoffcrypto-tool
库,进行自动移除excel文件密码
python
import msoffcrypto
# 已加密Excel文件路径
encrypted_file = "F:\解密前.xlsx"
# 未加密文件将保存的路径
unencrypted_file = "F:\解密后.xlsx"
# Excel文件密码
excel_password = "密码"
# 打开加密文件
with open(encrypted_file, "rb") as encrypted_file_fd:
office_file = msoffcrypto.OfficeFile(encrypted_file_fd)
# 使用密码解密
office_file.load_key(password=excel_password)
# 将解密内容写入新文件
with open(unencrypted_file, "wb") as unencrypted_file_fd:
office_file.decrypt(unencrypted_file_fd)
print(f"文件已解密并保存至:{unencrypted_file}")