package umm3601.digitalDisplayGarden;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

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

public class ExcelParser {
    private static final String FILE_NAME = "/home/Dogxx000/IdeaProjects/digital-display-garden-iteration-1-claudearabo/server/src/main/java/umm3601/digitalDisplayGarden/AccessionList2016.xlsx";

    public static void main(String[] args) {

        try {

            System.out.println("Attempting to read from file in: "+ new File(FILE_NAME).getCanonicalPath());
            FileInputStream excelFile = new FileInputStream(new File(FILE_NAME));

            Workbook workbook = new XSSFWorkbook(excelFile);
            Sheet datatypeSheet = workbook.getSheetAt(0);
            Iterator<Row> iterator = datatypeSheet.iterator();

            // ---------- our stuff -----------
            String[][] cellValues = new String[datatypeSheet.getLastRowNum()][];
            // ---------- our stuff -----------

            while (iterator.hasNext()) {

                Row currentRow = iterator.next();
                Iterator<Cell> cellIterator = currentRow.iterator();

                while (cellIterator.hasNext()) {

                    Cell currentCell = cellIterator.next();


                    //getCellTypeEnum shown as deprecated for version 3.15
                    //getCellTypeEnum ill be renamed to getCellType starting from version 4.0
                    if (currentCell.getCellTypeEnum() == CellType.STRING) {
                        System.out.print(currentCell.getStringCellValue() + "--");
                    } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
                        System.out.print(currentCell.getNumericCellValue() + "--");
                    }

                }
                System.out.println();

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

@@ -233,32 +233,64 @@
 io.IOException;%0A
+import java.lang.reflect.Array;%0A
 import java.util
@@ -1084,16 +1084,20 @@
 RowNum()
+ + 1
 %5D%5B%5D;%0A   
@@ -1109,81 +1109,219 @@
     
-// ---------- our stuff -----------%0A%0A            while (iterator.hasNext(
+Row currentRow = datatypeSheet.getRow(1);%0A            // ---------- our stuff -----------%0A%0A            Cell firstCell = iterator.next().getCell(1);%0A            while (iterator.hasNext() && !firstCell.equals(null
 )) %7B
@@ -1330,36 +1330,32 @@
                 
-Row 
 currentRow = ite
@@ -1430,32 +1430,131 @@
 ow.iterator();%0A%0A
+                cellValues%5BcurrentRow.getRowNum()%5D = new String%5BcurrentRow.getLastCellNum() - 1%5D;%0A%0A
                 
@@ -1969,32 +1969,160 @@
 alue() + %22--%22);%0A
+                        cellValues%5BcurrentCell.getRowIndex()%5D%5BcurrentCell.getColumnIndex()%5D = currentCell.getStringCellValue();%0A
                 
@@ -2265,32 +2265,168 @@
 alue() + %22--%22);%0A
+                        cellValues%5BcurrentCell.getRowIndex()%5D%5BcurrentCell.getColumnIndex()%5D = (%22%22 + currentCell.getNumericCellValue());%0A
                 
@@ -2485,24 +2485,25 @@
 println();%0A%0A
+%0A
             
@@ -2508,151 +2508,886 @@
   %7D%0A
-        %7D catch (FileNotFoundException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();
+%0A            System.out.println(cellValues.length);%0A            System.out.println(cellValues%5B1%5D.length);%0A            printDoubleArray(cellValues);%0A        %7D catch (FileNotFoundException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%0A    private static void printDoubleArray(String%5B%5D%5B%5D input)%7B%0A        for(int i = 1; i %3C input.length; i++)%7B%0A            if (!input%5Bi%5D.equals(null)) %7B%0A                for (int j = 0; j %3C input%5Bi%5D.length; j++) %7B%0A                    System.out.print(%22 %7C %22 + input%5Bi%5D%5Bj%5D );%0A                %7D%0A                System.out.println();%0A                System.out.println(%22-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------%22);%0A            %7D
 %0A   

Put xlsx data in 2D array, print 2D array WARNING: * Path is absolute to Lenny's account, need to fix * First row in 2d [0] is null, that's why the print function starts at 1. * Any cell with no value is null (mine field)