Apace POI is an API which was provided by Apache Foundation and is used to set the various type of values to the cell. The overloading function setCellValue() of Apache POI is used to set the value type of the cell. Maven is a powerful project management tool that is based on POM (project object model). It is used for project build, dependency, and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT.
Algorithm: Steps To Create Different Types of Cells In A Spreadsheet
- Step 1: Create an instance of the workbook
- Step 2: Create a spreadsheet in the above workbook.
- Step 3: Create rows using XSSFRow
- Step 4: Writing the content to the workbook by defining the object of type FileOutputStream
- Step 5: Close the file
Step 1: Create a Maven project in eclipse and add Apache POI(used for setting value type of cells) dependencies to it or a Java project with Apache POI library installed.
Step 2: As in creating a Maven project, prerequisites are required to add the following Maven dependencies to pom.xml file, in order to use the Apache POI library. For these libraries search online for Maven Central Library and then search for Apache POI and get the dependencies or can also copy the following dependencies as shown below to the main java program.
Step 3: After adding dependencies create a new class. For creating a new class go to src/main/java/package right-click and create a new class and name it, here for illustration purpose file is names as GFG. . In this class we will first create an instance of the workbook and with that instance, we will create a spreadsheet and in that spreadsheet, we will define the value type of cells. Below is the code snippet is given for the GFG class(taken here) as discussed above.
Implementation: Code snippet
Example: To create different types of cells in a spreadsheet
Output: A message will be printed in console as specified at last in the program that “GFG.xlsx Created Successfully” as the successful execution of the program responsible for changes in the spreadsheet below:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.