Last active
August 6, 2024 14:32
-
-
Save sbilodeau/276ab322e06e8813c31fd4260efe2978 to your computer and use it in GitHub Desktop.
Extract word metadate from word documents
This file contains hidden or 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
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