2015-08-27 12 views
0

I/P文件:DOC,DOCX与短破折号,破折号,通过使用Java我怎么能计算字数这给我造成同微软Office字数功能

我已经实现的功能的话通过使用Apache Tika计数(元数据属性)& Aspose wordtojava(库),但他们不给我准确的字数结果。

en-dash & em-dash字数不同于MS-Office ex。 2-3 4-5 结果: MS-办公室让字数4例如 上述APACHE - 提卡&的Aspose库给出字计数2

如何可以计算正确的单词由MS-给出计数相同办公室?

任何帮助是非常可观的。

需要快速响应。

谢谢

回答

2

从文档中提取所有字符串到一个字符串。 使用这个正则表达式“[\ n \ t \ r \ f \ p {Pd}]”来分割它们,并计算分割的字符串数组的长度。

String allWords = "2—3 4–5"; 
    String[] split = allWords.split("[\n\t\r\f \\p{Pd}]"); 
    System.out.println(split.length); 

它打印4. 希望得到这个帮助。

0

'BuiltInDocumentProperties.Words'属性表示Word文档中单词数的估计值。当您调用“Document.updateWordCount”方法时,Aspose.Words会更新此属性。请参阅下面的示例代码:

Document doc = new Document(getMyDir() + "in.docx"); 

// Update the word, character and paragraph count of the document. 
doc.updateWordCount(); 

// Display the updated document properties. 
System.out.println("Characters: " + doc.getBuiltInDocumentProperties().getCharacters()); 
System.out.println("Words: " + doc.getBuiltInDocumentProperties().getWords()); 
System.out.println("Paragraphs: " + doc.getBuiltInDocumentProperties().getParagraphs()); 

希望,这有助于。

此外,请确保您使用的是latest version of Aspose.Words for Java即15.7.0。

我使用Aspose作为Developer Evangelist。

+0

嗨Awais,我已经申请aspose代码如下&我正在使用最新的单词为java 15.7.0 – JalT

+0

我建议你请在[Aspose.Words论坛](http:// www .aspose.com/community/forums/aspose.words-product-family/75/showforum.aspx)与源文档和服务器代码结合使用。我们将在我们的最后详细调查问题,并通过您的线索为您提供更多信息。 –