2015-08-27 10 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)與源文檔和服務器代碼結合使用。我們將在我們的最後詳細調查問題,並通過您的線索爲您提供更多信息。 –