Hello,
I have noticed that BuiltInDocumentProperties.Words property (word count for the document) does not include footnotes/endnotes; and whereas MS Word has an option for including them in the word count, I find no such option in Aspose.Words.
Am I right? Is there a workaround? Can you plan to include such a feature?
Here is a small document to test this behaviour.
Best regards,
Claude Bédard
Hi
Thanks for your inquiry. Aspose.Words uses properties of document to get words count (File/Properties/ Statistics tab). MS Word doesn’t include footnotes into the document properties words count. If you need you can calculate words count programmatically.
Best regards.
Hi Alexey,
I am aware that basically MS Word does not include footnotes in the basic word count. However it does have a checkbox in the Statistics window to include them if required.
At least can you give me a clue as to how I can do this programmatically?
Also, could you consider adding such an option in future release of Aspose.Words?
Best regards,
Claude
Hi
I didn’t tell that there is no option in MS Word to include footnotes into the words count. I just tell that this option doesn’t work for document properties.
You can try using the following code to calculate words count.
// Open document
Document doc = new Document(@"Test232\in.doc");
// update words count in document
doc.UpdateWordCount();
// Get collection of footnotes
NodeCollection notes = doc.GetChildNodes(NodeType.Footnote, true);
int wordsInNotes = 0;
foreach (Footnote note in notes)
{
// Get collection of runs from the current footnote
NodeCollection runs = note.GetChildNodes(NodeType.Run, true);
// Calculate words count in each run
foreach (Run run in runs)
{
string[] words = run.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
wordsInNotes += words.Length;
}
}
// Get words count including footnotes
int wordsCount = doc.BuiltInDocumentProperties.Words + wordsInNotes;
Best regards.
Hi Alexey,
I have a great deal of respect for the work involved with creating such a complex tool as Aspose.Word, but I tried my luck at “why not another feature”.
Thank you for the workaround, it should do the job.
Best regards,
Claude