java excel read sample

import java.io.FileInputStream;

import java.util.ArrayList;

import java.util.List;

 

import org.apache.poi.hssf.usermodel.HSSFSheet;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.ss.usermodel.Row;

 

public class xlsReader {

 

public static void main(String[] args) throws Exception {

 

// TODO 自動生成されたメソッド・スタブ

 List <beanUser> lbu = new ArrayList<beanUser>();

 //Path of the excel file

 FileInputStream fs = new FileInputStream("userlistm.xls");

 //Creating a workbook XSSF for ver 2007 after

 HSSFWorkbook workbook = new HSSFWorkbook(fs);

 HSSFSheet sheet = workbook.getSheetAt(0);

 int cnt = 0;

 while(true) {

   beanUser bu = new beanUser();

   Row row = sheet.getRow(cnt);

   if(row==null) { 

   break;

   }

  Cell cell = row.getCell(0);

  System.out.println(cell.getAddress());

  bu.setId(cell.getStringCellValue());

  cell = row.getCell(1);

  bu.setName(cell.getStringCellValue());

  cell = row.getCell(2);

  bu.setAge(cell.getStringCellValue());

  cell = row.getCell(3);

  bu.setBirth(cell.getStringCellValue());

  lbu.add(bu);

  cnt++;

}

  lbu.stream().forEach(id -> System.out.println(id.getId()+

  id.getName()+id.getAge()+id.getBirth()));

 

}

 

}