Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.6 kB
1
Indexable
Never
//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.FormulaEvaluator;  
import org.apache.poi.ss.usermodel.Row;  
import org.apache.poi.xssf.usermodel.XSSFSheet;  
import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
import java.io.File;  
import java.io.FileInputStream;  
import java.util.*;
import java.io.*;


public class ReadExcel {
    public static void main(String args[]) throws IOException {

        FileInputStream fileinput = new FileInputStream(new File("dummy.xlsx")); 
        XSSFWorkbook workbookxss = new XSSFWorkbook(fileinput);   
        XSSFSheet sheet = workbookxss.getSheetAt(0);     
        Iterator<Row> it_sheet = sheet.iterator();      
        while (it_sheet.hasNext())
        {
            Row row = it_sheet.next();
            Iterator<Cell> it_cell = row.cellIterator();
            while (it_cell.hasNext())
            {   

                Cell cell = it_cell.next();  
                if (cell.getColumnIndex() == 2)
                    break;
                if (cell.getCellType() == Cell.CELL_TYPE_STRING)
                    System.out.print(cell.toString() + "\t\t\t");  
                else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC)
                    System.out.print(cell + "\t\t\t");
                else   
                    System.out.println("Incorrect cell format!");
    
             }   

        }
        System.out.print("\n");
        workbookxss.close();
        fileinput.close();
    }
}