Drop Down

Tuesday, April 9, 2019

Read from Excel

package upload_download_Excel_Bakchodi;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

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;

public class Excel_1
{
public static void main(String[] args) throws IOException
{
FileInputStream fis = new FileInputStream(new File("D:\\work\\Java Work Space\\files\\demo.xlsx"));

//create workbook instance that refers to .xls file
XSSFWorkbook wb = new XSSFWorkbook(fis);

//create sheet object to retrive sheet
XSSFSheet sheet = wb.getSheetAt(0);

//that is for evaluate the cell type
FormulaEvaluator formula = wb.getCreationHelper().createFormulaEvaluator();

for(Row row : sheet)
{
for(Cell cell : row)
{

switch(formula.evaluateInCell(cell).getCellType())
{
case STRING:
System.out.print(cell.getStringCellValue()+"\t\t");
break;
case NUMERIC:
System.out.print(cell.getNumericCellValue()+"\t\t");
break;
}

}
System.out.println();
}



}

}
========================================================================
Note : Download POI .Jars  from below link

Binary Distribution

No comments:

Post a Comment

Java 8 Notes Pics