Skip to content

Instantly share code, notes, and snippets.

@sbilodeau
Last active August 6, 2024 14:32
Show Gist options
  • Save sbilodeau/276ab322e06e8813c31fd4260efe2978 to your computer and use it in GitHub Desktop.
Save sbilodeau/276ab322e06e8813c31fd4260efe2978 to your computer and use it in GitHub Desktop.
Extract word metadate from word documents
Word oWord = new Word()
Microsoft.Office.Interop.Word.Document doc = oWord.OpenDocument(sourcePath);
var props = oWord.GetProperties(doc);
var result = new JSonObject()
result["symbol"] = props.Get<string>("Symbol") ?? "";
result["title"] = props.Get<string>("Title") ?? "";
result["subject"] = props.Get<string>("Subject") ?? "";
result["company"] = props.Get<string>("Company") ?? "";
result["keywords"] = props.Get<string>("Keywords") ?? "";
result["comments"] = props.Get<string>("Comments") ?? "";
result["trackRevisions"] = doc.TrackRevisions;
result["hasComments"] = doc.Comments.Count!=0;
result["pageCount"] = doc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages);
result["wordCount"] = doc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticWords, true);
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment