OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. The library has more than 2500 optimized algorithms, which includes a comprehensive set of both classic and state-of-the-art computer vision. It has C++, Python, Java, and MATLAB interfaces and supports Windows, Linux, Android, and Mac OS.
OpenCV provides us various classes and interfaces to add/create a document in word. In, this article, we will be discussing all these classes as well as their implementation and the steps that how can we add word document using Java.
Accessing word file using java
A Jar file is an Zip archive containing one or multiple java class files. This makes the usage of libraries (consisting of multiple classes) more handy. Directories and Jar files are added to the classpath and available to the ClassLoader at runtime to find particular classes inside of it. We generally use .jar files to distribute Java applications or libraries, in the form of Java class files and associated metadata and resources (text, images, etc.). you can say JAR = Java ARchive.
We can read or access a java file using apache poi
Step 1: Download Apache POI API. You can download it from here
Step 2: Import .jar files. Extract jar files for your project, and add the following jar to your build path:
Step 3: Create a new java file to write the code in it and add it to your project
Java classes for adding a table
- used to create a document
- used to create a simple table
- used to add row to the table
Procedure: Below are the steps to implement the classes to add a document using Java
Step 1: Import classes like XWPFDocument, XWPFTable, XWPFTableRow of io.File package which helps in creating a document, adding the table to the document, and then adding rows to it.
Step 2: Create a document using class XWPFDocument and store it in a variable
Step 3: Create table using class XWPFTable
Step 4: Add rows
Add rows using class XWPFTableRow. We can add as much row as we want to and every time before creating a new row, we have to call the class XWPFTableRow
Sample input Image: In which rows are to be inserted
XWPFDocument document =
FileOutputStream out =
XWPFTable table = document.createTable();
XWPFTableRow tableRowOne = table.getRow(
XWPFTableRow tableRowTwo = table.createRow();
XWPFTableRow tableRowThree = table.createRow();
"create_table.docx written successfully"
Output: Image adding up rows in the input
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!