在使用Word时,当输入字符或者文本时,Word会自定对输入的文字进行统计,这个功能在实际应用中也会经常用到,Spire.Doc for.NET是一款经典的Word文档处理控件,同样也为开发人员提供了该统计功能,下面就怎么使用代码进行Word文档字数以及页面的统计做简单介绍,具体代码如下:
C#
Document doc = new Document();
doc.LoadFromFile("test.docx", FileFormat.Docx2010);
Console.WriteLine("CharCount: " + doc.BuiltinDocumentProperties.CharCount);
Console.WriteLine("CharCountWithSpace: " + doc.BuiltinDocumentProperties.CharCountWithSpace);
Console.WriteLine("WordCount: " + doc.BuiltinDocumentProperties.WordCount);
Console.ReadKey();
VB.NET
Dim doc As New Document()
doc.LoadFromFile("test.docx", FileFormat.Docx2010)
Console.WriteLine("CharCount: " + doc.BuiltinDocumentProperties.CharCount)
Console.WriteLine("CharCountWithSpace: " + doc.BuiltinDocumentProperties.CharCountWithSpace)
Console.WriteLine("WordCount: " + doc.BuiltinDocumentProperties.WordCount)
Console.ReadKey()