0
package com.excel;

import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadExcelDemo {

    public static void main(String[] args) {
          try
            {
                FileInputStream file = new FileInputStream(new File("howtodoinjava.xlsx"));

                //Create Workbook instance holding reference to .xlsx file
                XSSFWorkbook workbook = new XSSFWorkbook(file);

                //Get first/desired sheet from the workbook
                XSSFSheet sheet = workbook.getSheetAt(0);

                //Iterate through each rows one by one
                Iterator<Row> rowIterator = sheet.iterator();
                while (rowIterator.hasNext())
                {
                    Row row = rowIterator.next();
                    //For each row, iterate through all the columns
                    Iterator<Cell> cellIterator = row.cellIterator();

                    while (cellIterator.hasNext())
                    {
                        Cell cell = cellIterator.next();
                        //Check the cell type and format accordingly
                        switch (cell.getCellType())
                        {
                            case Cell.CELL_TYPE_NUMERIC:
                                System.out.print(cell.getNumericCellValue() + "t");
                                break;
                            case Cell.CELL_TYPE_STRING:
                                System.out.print(cell.getStringCellValue() + "t");
                                break;
                        }
                    }
                    System.out.println(""); 
                }
                file.close();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    }
}

I m Created one Excel Report inserted some Data through maven java program . I want to read that Data through maven java Program in excel report. This is for a new maven java program running on eclipse IDE,In the past , i have tried on XML file poi 4.0.0 version and always seem to end up having to fall back to 4.0.1.

Abhishek Tiwari
  • 332
  • 2
  • 16
Rakesh
  • 27
  • 11
  • 5
    Possible duplicate of [How to read and write excel file](https://stackoverflow.com/questions/1516144/how-to-read-and-write-excel-file) – Nomce Apr 10 '19 at 07:11
  • The code looks correct. What error you get in what code line? Stack trace please. And " i have tried on XML file poi 4.0.0 version and always seem to end up having to fall back to 4.0.1" is pretty unclear. Version `4.0.1` is the follow up version of `4.0.0`. So what is meant with "fall back"? – Axel Richter Apr 11 '19 at 03:50

0 Answers0