import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import java.io.*;
import java.util.*;
import javax.swing.*;
// reading from excel
public class apachePOI2
{
public static String[][] read_String_from_excel1(String filename, int pageno)
{
    Workbook Work=wb(filename);
    String s[][]=new String [2000][2000];
    int i=0,j=0,i1=0,j1=0;
    Sheet sheet1 = Work.getSheetAt(pageno);
    Iterator rowItr = sheet1.rowIterator();  
    while ( rowItr.hasNext() ) 
    {   j=0;
	    Row row = (Row) rowItr.next();             
        Iterator cellItr = row.cellIterator();
        while ( cellItr.hasNext() ) 
        { s[i][j]=toString(cellItr);
          //in case of an empty line stop iteration
          if(s[i][j].charAt(0)==' ') {i=i1;j=j1;break;}
          //System.out.print("i="+i+"j="+j+"*"+s[i][j]+"* ");
          j++;j1=j;
        } 
   i++;i1=i;
   }
   int n=i1;
   int m=j1;
   String s1[][]=new String [n][m];
   for(i=0;i<n;i++)
   {for(j=0;j<m;j++)
     {s1[i][j]=s[i][j];}
   }
   return s1;	
}

public static String toString(Iterator cellItr)
{
            String s="";
            Cell cell = (Cell) cellItr.next();
            if(cell.getCellType()==Cell.CELL_TYPE_BOOLEAN) 
            { s=cell.getBooleanCellValue() + "\t\t";}
            else if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC)
            { s=cell.getNumericCellValue() + "\t\t";}
            else if(cell.getCellType()==Cell.CELL_TYPE_STRING)
            {s=cell.getStringCellValue() + "\t\t";}
            else if(cell.getCellType()==Cell.CELL_TYPE_FORMULA)
            {s=cell.getNumericCellValue() + "\t\t";}
            return s;
}
     public static String word(String s)
     {  //returns extension group of file name 
     StringTokenizer token=new StringTokenizer(s,".");
     int m=token.countTokens();
     String b[]=new String[m];
     int j=0;           
     while(token.hasMoreTokens())
     {
     String ax=(String)token.nextToken();
     b[j++]=ax;
     }
     return b[m-1];
     }
public static Workbook wb(String filename)
{
    String s2=word(filename);
    Workbook Work=new HSSFWorkbook();
    try {   
     FileInputStream inputStr= new FileInputStream(filename);
    if(s2.equals("xls"))
    {Work=new HSSFWorkbook(inputStr);}
    else
    {Work= new XSSFWorkbook(inputStr) ;} 
    } catch (Exception e) {e.printStackTrace();} 
    return Work;	
}    

public static void main(String arg[])
{    
     String s[][]=read_String_from_excel1("DATA1.xls",0);
     JTableP.print(s);
}}
