Creating a Cell at specific position in Excel file using Java
Apache POI can be used to create a cell in a Given Excel file at specific position. Apache POI is an API provided by Apache foundation.
Steps to Create a Cell at specific position in a given Excel File:
- Create a maven project(Maven is a build automation tool used primarily for Java projects) in eclipse or a Java project with POI library installed
- Add following maven dependency in pom.xml file
<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.12</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.12</version></dependency> - Write java code in javaresource folder
importjava.io.*;importorg.apache.poi.hssf.usermodel.HSSFWorkbook;importorg.apache.poi.ss.usermodel.Cell;importorg.apache.poi.ss.usermodel.Row;importorg.apache.poi.ss.usermodel.Sheet;importorg.apache.poi.ss.usermodel.Workbook;publicclassCreateCellAtSpecificPosition {publicstaticvoidmain(String[] args)throwsFileNotFoundException, IOException{// Create a workbook instancesWorkbook wb =newHSSFWorkbook();OutputStream os =newFileOutputStream("Geeks.xlsx");// Creating a sheet using predefined class provided by Apache POISheet sheet = wb.createSheet("Company Prepration");// Creating a row at specific position// using predefined class provided by Apache POI// Specific row numberRow row = sheet.createRow(1);// Specific cell numberCell cell = row.createCell(1);// putting value at specific positioncell.setCellValue("Geeks");// writing the content to Workbookwb.write(os);System.out.println("given cell is created at position (1, 1)");}}
Output
given cell is created at position (1, 1)
Output in Geeks.xlsx File
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.


