Read Excel File Example
This program demonstrates reading data from an Excel file.
Problem Statement
Write a Java program that reads rows and columns from an Excel file using Apache POI.
Source Code
| 1 | import java.io.*; |
| 2 | import org.apache.poi.ss.usermodel.*; |
| 3 | public class ReadExcelExample { |
| 4 | public static void main(String[] args) { |
| 5 | System.out.println("Eduinq Read Excel Example"); |
| 6 | try(FileInputStream fis=new FileInputStream("data.xlsx")) { |
| 7 | Workbook wb=WorkbookFactory.create(fis); |
| 8 | Sheet sheet=wb.getSheetAt(0); |
| 9 | for(Row row:sheet){ |
| 10 | for(Cell cell:row){ |
| 11 | System.out.print(cell+" | "); |
| 12 | } |
| 13 | System.out.println(); |
| 14 | } |
| 15 | } catch(Exception e) { |
| 16 | System.out.println("Eduinq Exception: "+e.getMessage()); |
| 17 | } |
| 18 | } |
| 19 | } |
Program Output
Eduinq Read Excel Example 1 | Arun | India | 2 | Priya | USA |
Explanation
Apache POI provides WorkbookFactory for reading Excel files. - Iterates rows and cells to print values. - Exception handling ensures safe operations. - In enterprise systems, Excel reading is used for importing structured reports. Conclusion: Shows reading Excel files.