Skip to content
Related Articles

Related Articles

Improve Article

Creating a Cell at specific position in Excel file using Java

  • Difficulty Level : Medium
  • Last Updated : 27 Sep, 2018
Geek Week

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:

  1. 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
  2. Add following maven dependency in pom.xml file

  3. Write java code in javaresource folder

    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    public class CreateCellAtSpecificPosition {
        public static void main(String[] args) throws FileNotFoundException, IOException
            // Create a workbook instances
            Workbook wb = new HSSFWorkbook();
            OutputStream os = new FileOutputStream("Geeks.xlsx");
            // Creating a sheet using predefined class provided by Apache POI
            Sheet sheet = wb.createSheet("Company Prepration");
            // Creating a row at specific position
            // using predefined class provided by Apache POI
            // Specific row number
            Row row = sheet.createRow(1);
            // Specific cell number
            Cell cell = row.createCell(1);
            // putting value at specific position
            // writing the content to Workbook
            System.out.println("given cell is created at position (1, 1)");


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.

My Personal Notes arrow_drop_up