Skip to content

Instantly share code, notes, and snippets.

@robinfang
Created November 19, 2020 07:37
Show Gist options
  • Save robinfang/8978f1b14f5a50f7b8a1d4e6efccccb3 to your computer and use it in GitHub Desktop.
Save robinfang/8978f1b14f5a50f7b8a1d4e6efccccb3 to your computer and use it in GitHub Desktop.
删除word文件元数据中的作者信息的脚本。
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