Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. // import statements
  2. public class POIforgfgRead {
  3. public static void main(String[] args)
  4.     {
  5.         try {
  6.             FileInputStream file = new FileInputStream(new File("gfgcontribute.xlsx"));
  7.  
  8.             // Create Workbook instance holding reference to .xlsx file
  9.             XSSFWorkbook workbook = new XSSFWorkbook(file);
  10.  
  11.             // Get first/desired sheet from the workbook
  12.             XSSFSheet sheet = workbook.getSheetAt(0);
  13.  
  14.             // Iterate through each rows one by one
  15.             Iterator<Row> rowIterator = sheet.iterator();
  16.             while (rowIterator.hasNext()) {
  17.                 Row row = rowIterator.next();
  18.                 // For each row, iterate through all the columns
  19.                 Iterator<Cell> cellIterator = row.cellIterator();
  20.  
  21.                 while (cellIterator.hasNext()) {
  22.                     Cell cell = cellIterator.next();
  23.                     // Check the cell type and format accordingly
  24.                     switch (cell.getCellType()) {
  25.                     case Cell.CELL_TYPE_NUMERIC:
  26.                         System.out.print(cell.getNumericCellValue() + "t");
  27.                         break;
  28.                     case Cell.CELL_TYPE_STRING:
  29.                         System.out.print(cell.getStringCellValue() + "t");
  30.                         break;
  31.                     }
  32.                 }
  33.                 System.out.println("");
  34.             }
  35.             file.close();
  36.         }
  37.         catch (Exception e) {
  38.             e.printStackTrace();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement