1. 安装Spire.Doc for Python
pip install Spire.Doc
2. 实例
目录内的所有Word文档移除编辑限制
import os
from spire.doc import *
from spire.doc.common import *
path = '.\\test'
for filepath,dirnames,filenames in os.walk(path):
for filename in filenames:
if filename[-3:] == 'doc' or filename[-4:] == 'docx':
print(os.path.join(filepath,filename))
doc = Document()
doc.LoadFromFile(os.path.join(filepath,filename))
doc.Protect(ProtectionType.NoProtection)
doc.SaveToFile(os.path.join(filepath,filename))
doc.Close()
标签:Word,filepath,python,doc,filename,文档,path,os
From: https://www.cnblogs.com/wstong2052/p/17874631.html