python给excel加密,给文件设置为只可读不可编辑,若编辑则需要密码
from xlsxwriter.workbook import Workbook
book = Workbook(r"新excel文件路径")
sheet = book.add_worksheet('ceshi') #添加sheet
# Add separate format for unlocked cells
# unlocked = book.add_format({'locked': 0})
# Protect all cells in your sheet by default
sheet.protect('密码')
# Write cell, locked by default
sheet.write(0, 0, 'aaa') # 行,列,数据
# sheet.write(row_number, column_number, data, unlocked)
book.close()
# 获取文件路径
def get_file_path(rootdir):
pathname = []
for (dirpath, dirnames, filenames) in os.walk(rootdir):
for filename in filenames:
# print(os.path.join(dirpath, filename))
pathname.append(os.path.join(dirpath, filename))
return pathname