-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcelReader.java
More file actions
55 lines (42 loc) · 1.46 KB
/
ExcelReader.java
File metadata and controls
55 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 ExcelReader {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileInputStream fis = new FileInputStream(new File("C:/Users/ckr/Desktop/workbook.xlsx"));
// create a workbook instance that refers to .xls file
XSSFWorkbook wb = new XSSFWorkbook(fis);
// create a sheet object to retrieve the sheet
XSSFSheet Sheet = wb.getSheetAt(0);
//For Evaluating The Cell Type
FormulaEvaluator forlulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
for(Row row : Sheet) {
for(Cell cell : row){
switch(forlulaEvaluator.evaluateInCell(cell).getCellType())
{
//if cell is a numeric value
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue()+"\t\t");
break;
//if cell is a string value
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue()+"\t\t");
break;
}
}
System.out.println(); }
}
}