Created
November 19, 2020 07:37
-
-
Save robinfang/8978f1b14f5a50f7b8a1d4e6efccccb3 to your computer and use it in GitHub Desktop.
删除word文件元数据中的作者信息的脚本。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from docx import Document | |
import sys | |
from pathlib import Path | |
def dump(obj): | |
for attr in dir(obj): | |
print("obj.%s = %r" % (attr, getattr(obj, attr))) | |
def delMeta(file): | |
document = Document(file) | |
cp = document.core_properties | |
dump(cp) | |
cp.author = "" | |
cp.last_modified_by = "" | |
print("after") | |
dump(cp) | |
basename = Path(file).stem | |
document.save(basename + "_no_meta.docx") | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print("usage: python {} xx.docx".format(sys.argv[0])) | |
sys.exit() | |
else: | |
delMeta(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment