Count the Number of Words in a Word Document Using Java

Import JAR Dependency


Sample Code

import com.spire.doc.*;

public class countWordsNumber {
public static void main(String[] args) {
//Create a Document instance
Document document = new Document();

//Load a sample Word document
document.loadFromFile("Input 1.docx");

//Count the number of words
System.out.println("WordCount: " + document.getBuiltinDocumentProperties().getWordCount());

//Count the number of characters without spaces
System.out.println("CharCount: " + document.getBuiltinDocumentProperties().getCharCount());

//Count the number of characters with spaces
System.out.println("CharCountWithSpace: " + document.getBuiltinDocumentProperties().getCharCountWithSpace());




Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Three Dominoes

Using SOPS and git hooks to share secrets — Part 1

Complexity in Software Architecture: Decompose for Simplicity

SQL Server — Table size sp_msforeachtable

Go bits: Magic with functions

How to install an SSL Certificate on Sentora?

iOS Architecture: A State Container based approach

The Utility of Manual Processes In Programming

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Exception Handling in java

Add Superscript and Subscript to PowerPoint Using Java

How to Validate a PNG File with Java

TIL 0630 Head First Java CH6. Get to Know The Java API: Using the Java Library