Word Count & Return all words from Document

Hi all,

i'm evaluating the Syncfusion.DocIO coz' we need a logic to get every word in a *.doc file as a single string object. How can this be done?

Can this work like the following example (i know this is not a working one ;-)

'---------------------------------------------
Function GetWords() As ArrayList

Dim wordsArray As New ArrayList
Dim currentWord As String

Dim document As DocIO.DLS.WordDocument = _
New DocIO.DLS.WordDocument

document.Open(fileName, FormatType.Doc)

For Each currentWord In document.GetText
wordsArray.Add(currentWord)
Next

Return wordsArray
End Function
'---------------------------------------------

Your help is much appreciated...
Regards,
Mac


1 Reply

AD Administrator Syncfusion Team January 14, 2008 06:47 AM UTC

Hi Mac,

Thank you for evaluating Syncfusion products.

Word count

You can display number of words in a document using WordCount property of document as follows.

[C#]

doc.BuiltinDocumentProperties.WordCount

To return all the words in a document

We don't have direct support for displaying all the words in a document. You need to enumerate the document elements starting from sections and need to check whether each paragraph item in the section contains any Text to display. Here is a code snippet.

[C#]

// Enumerate the document elements starting from sections
foreach (IWSection sec in doc.Sections)
{
foreach (IWParagraph para in sec.Paragraphs)
{
for (int i = 0; i < para.ChildEntities.Count; i++)
{
Syncfusion.DocIO.DLS.IParagraphItem pItem = para[i] as Syncfusion.DocIO.DLS.IParagraphItem;

//Check if the type of element is a text
if (pItem is IWTextRange)
{
IWTextRange cellText = pItem as IWTextRange;
String s = cellText.Text.ToString();
Console.WriteLine(s.ToString());

}

}
}

Finally , you can display all the words in a string IWTextRange.Text.

Sample reference

Please refer the sample that demonstrates the same.

http://websamples.syncfusion.com/samples/DocIO.Windows/F71041/main.htm

Please let me know if this helps you.

Regards,
Jaya





Loader.
Up arrow icon