DocumentUpdateWordCount Method (Boolean) |
Namespace: Aspose.Words
// Create an empty document Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("This is the first line."); builder.Writeln("This is the second line."); builder.Writeln("These three lines contain eighteen words in total."); // The fields that keep track of how many lines and words a document has are not automatically updated // An empty document has one paragraph by default, which contains one empty line Assert.AreEqual(0, doc.BuiltInDocumentProperties.Words); Assert.AreEqual(1, doc.BuiltInDocumentProperties.Lines); // To update them we have to use this method // The default constructor updates just the word count doc.UpdateWordCount(); Assert.AreEqual(18, doc.BuiltInDocumentProperties.Words); Assert.AreEqual(1, doc.BuiltInDocumentProperties.Lines); // If we want to update the line count as well, we have to use this overload doc.UpdateWordCount(true); Assert.AreEqual(18, doc.BuiltInDocumentProperties.Words); Assert.AreEqual(3, doc.BuiltInDocumentProperties.Lines);