how to read a excel file in java

Solutions on MaxInterview for how to read a excel file in java by the best coders in the world

showing results for - "how to read a excel file in java"
Anael
27 Sep 2018
1//You need Apache POI library in order to work this code
2
3//Using Apache POI
4    import java.io.File;  
5    import java.io.FileInputStream;  
6    import java.io.IOException;  
7    import org.apache.poi.hssf.usermodel.HSSFSheet;  
8    import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
9    import org.apache.poi.ss.usermodel.Cell;  
10    import org.apache.poi.ss.usermodel.FormulaEvaluator;  
11    import org.apache.poi.ss.usermodel.Row;  
12    public class ReadExcelFileDemo  
13    {  
14    public static void main(String args[]) throws IOException  
15    {  
16    //obtaining input bytes from a file  
17    FileInputStream fis=new FileInputStream(new File("C:\\demo\\student.xls"));  
18    //creating workbook instance that refers to .xls file  
19    HSSFWorkbook wb=new HSSFWorkbook(fis);   
20    //creating a Sheet object to retrieve the object  
21    HSSFSheet sheet=wb.getSheetAt(0);  
22    //evaluating cell type   
23    FormulaEvaluator formulaEvaluator=wb.getCreationHelper().createFormulaEvaluator();  
24    for(Row row: sheet)     //iteration over row using for each loop  
25    {  
26    for(Cell cell: row)    //iteration over cell using for each loop  
27    {  
28    switch(formulaEvaluator.evaluateInCell(cell).getCellType())  
29    {  
30    case Cell.CELL_TYPE_NUMERIC:   //field that represents numeric cell type  
31    //getting the value of the cell as a number  
32    System.out.print(cell.getNumericCellValue()+ "\t\t");   
33    break;  
34    case Cell.CELL_TYPE_STRING:    //field that represents string cell type  
35    //getting the value of the cell as a string  
36    System.out.print(cell.getStringCellValue()+ "\t\t");  
37    break;  
38    }  
39    }  
40    System.out.println();  
41    }  
42    }  
43    }  
queries leading to this page
parsing excel file in javajava best way to read from excel fileshandle excel file with javareading excel file javajava code to read excel fileread an excel sheet in javaread an excel file in javahow to read excel data in javaread excel java examplejava read excel file module libraryreading excel files in javafastest way to write excel file in javaread and write excel file in javahow to parse an excel file in javareading from excel in javahow to read excel sheet in javahow to open a excel file from javaread data excel javaread excel fil in javahow to get read data from excel file in javajava read excel file and updatejava program to read an excel filejava code to read excel file formulajava read excelljava read excelreading the data from excel using javahow create excel file in javajava read excel filehow to read excel file in java using eclipsejava read from excel filejava open and read excel using only javahow to read excel file in java 8importing excel files into javahow to read and write to an excel sheet in javareading an excel file in javajava open and read excelhow to make excel file in javahow read excel file in javajava read excel file libraryjava open excel fileread excel file from javaexcel file reading code in javajava library to read excel filesread file excel javareading excel file in javahow to read from an excel file in javajava read from excelread excel files javajava code to read excel formulajava import excel filefunction to read excel file in javahow to read the excel file in java 8 by mkyonghow to read excel files in javahow to read excel files javahow to read data from excel file in javajava to read excel fileread excel file java coderead excel file javaread excel in javahow to read the excel file in java 8how to read in a excel file using javajava read excel fielhow to open excel file in javajava read excel file with headersread excel to javaapi to read excel file in javaopen excel file javaread excel file in javahow to read data from excel in javahow to read a excel file in javahow to read excel file in javajava read excel file xlsxhow to read a excel file in java