【发布时间】:2018-07-27 17:53:22
【问题描述】:
我目前正在实施一种工具来自动化我的部分日常工作。因此,我需要创建一个 python 工具来创建一个包含多个信息的 excel 文件(工作簿)并加密文件的工作表。 创建文件并用数据填充文件的第一部分工作得很好。
但是加密根本不起作用。 我正在使用 win32com、win32com.client 和 openpyxl。工作簿有两个不同的工作表,分别命名为“1”和“2”。
我的工作簿:
import win32com.client
import os, sys, win32com, os.path, time
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible = True
workbook = excel.Workbooks.Open(reading_path) ####this is the path where the file is stored
sheet = workbook.Worksheets(1)
于是我搜索了其他主题,得到了以下信息:
import openpyxl
sheet.protection.set_password('test')
sheet.save(saving_path)
不幸的是,这不起作用...我的 shell 响应一个 AttributeError。详细:
AttributeError: <unknown>.set_password
有人知道如何用 python 只加密 excel 中的页面吗?
非常感谢您的帮助!
【问题讨论】:
标签: python excel encryption openpyxl win32com