Example usage for org.apache.poi.ss.usermodel Cell getNumericCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell getNumericCellValue

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell getNumericCellValue.

Prototype

double getNumericCellValue();

Source Link

Document

Get the value of the cell as a number.

Usage

From source file:FileHelper.ExcelHelper.java

private Object GetValueFromCell(Cell cell, String typeName) {
    if (typeName.equals("String")) {
        return cell.getStringCellValue();
    } else if (typeName.equals("Integer")) {
        Double d = cell.getNumericCellValue();
        return Integer.toString(d.intValue());
    }//from  w ww  .j  av a2s. co m
    return null;
}

From source file:FileHelper.ExcelHelper.java

private String GetValueStringFromCell(Cell cell) {
    String str = "";
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING: {
        str = cell.getStringCellValue();
        break;//from  w  w w .j  a va2  s. c  o  m
    }
    case Cell.CELL_TYPE_NUMERIC: {
        Double d = cell.getNumericCellValue();
        str = Integer.toString(d.intValue());
        break;
    }
    }
    return str;
}

From source file:FileHelper.ExcelHelper.java

private int GetValueIntegerFromCell(Cell cell) {
    int result = -1;
    switch (cell.getCellType()) {
    case Cell.CELL_TYPE_STRING: {
        result = Integer.parseInt(cell.getStringCellValue());
        break;/*from   www .  j  a  v  a  2 s  .  c  o  m*/
    }
    case Cell.CELL_TYPE_NUMERIC: {
        Double d = cell.getNumericCellValue();
        result = d.intValue();
        break;
    }
    }
    return result;
}

From source file:Files.XLSX2BatchHandler.java

public void exportBatchFile(String xlsxFileName, String batchFileName) throws IOException {
    File myFile = new File(xlsxFileName);

    FileOutputStream outputFile = new FileOutputStream(batchFileName); //allow to append
    PrintStream output = new PrintStream(outputFile);
    try {//w  w  w  .j  a va2  s.c om
        FileInputStream fis = new FileInputStream(myFile);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);

        //Return first sheet from the XLSX workbook
        XSSFSheet mySheet = myWorkBook.getSheetAt(0);
        List<String> errorList = new ArrayList<>();
        Map<String, Map<String, List<String>>> leaves = new HashMap<String, Map<String, List<String>>>();
        //Get iterator to all the rows in current sheet
        Iterator<Row> rowIterator = mySheet.iterator();
        int lineCount = 1;
        // Traversing over each row of XLSX file
        if (rowIterator.hasNext()) {

            Row headerRow = rowIterator.next(); //skip the header row
            Iterator<Cell> it = headerRow.cellIterator();
            int numCell = 0;
            List<String> keyList = new ArrayList<String>(); //keep track info of each column

            while (it.hasNext()) {
                keyList.add(it.next().getStringCellValue()); // add the title in xlsx to keyList                  
                numCell++;
            }
            System.out.println("XLSX2BatchHandler.java UCFR loaded = " + DB.isUCFRLoaded());
            if (numCell == GlobalVar.LEAVE_TITLES_V1.length && DB.isUCFRLoaded()) { // check if the excel is the leave roster
                System.out.println("XLSX2BatchHandler.java:  V1, UCFR is loaded.");
                int globalCount = 1;
                while (rowIterator.hasNext()) {
                    lineCount++;
                    Row row = rowIterator.next();
                    Iterator<Cell> cellIterator = row.cellIterator();
                    Map<String, String> container = new HashMap<>();
                    int keys = 0; //index of the cell
                    // reset date every row
                    while (cellIterator.hasNext()) {
                        Cell cell = cellIterator.next();
                        if (keys == GlobalVar.CTRL_NUM_CELL_INDEX_V1
                                || keys == GlobalVar.LAST_NAME_CELL_INDEX_V1) {
                            String value = cell.getStringCellValue();
                            container.put(keyList.get(keys), value);
                        } else if (keys == GlobalVar.LAST4_CELL_INDEX_V1) {
                            DataFormatter df = new DataFormatter();
                            //SimpleDateFormat fmt = new SimpleDateFormat("yyMMdd");   
                            String lastFour = df.formatCellValue(cell); //return ***-**-****
                            lastFour = GlobalVar.last4Generator(lastFour);
                            container.put(keyList.get(keys), lastFour);
                        } else if (keys == GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V1
                                || keys == GlobalVar.SIGN_IN_DATE_CELL_INDEX_V1) {
                            DataFormatter df = new DataFormatter();
                            String dateString = df.formatCellValue(cell);
                            container.put(keyList.get(keys), dateString);
                        } else if (keys == GlobalVar.LEAVE_AREA_CELL_INDEX_V1) {
                            int type = cell.getCellType();
                            String value = null;
                            if (type == HSSFCell.CELL_TYPE_STRING) {
                                value = GlobalVar.getDMOLeaveArea(cell.getStringCellValue());
                            } else if (type == HSSFCell.CELL_TYPE_NUMERIC) {
                                value = GlobalVar.getDMOLeaveArea(cell.getNumericCellValue()); //read a double and return string
                            }
                            container.put(keyList.get(keys), value);
                        } else if (keys == GlobalVar.LEAVE_TYPE_CELL_INDEX_V1) {
                            String value = GlobalVar.getDMOLeaveType(cell.getStringCellValue());
                            container.put(keyList.get(keys), value);
                        }
                        keys++;
                    }

                    //    public static final String[] SIGNED_LEAVE_TITLES = {"Ctrl Number", 
                    //            "SSN", "Last Name", "Sign-in Date", "Sign-out Date", "Leave Area",
                    //        "Leave Type", "Num of Days", "First Five","Projected Sign-in Date", "Projected Sign-out Date"};
                    //      make sure the key mataches the name in the header

                    String ctrlNum = GlobalVar
                            .readCtrlNum(container.get(keyList.get(GlobalVar.CTRL_NUM_CELL_INDEX_V1)));
                    if (ctrlNum == null) {
                        JOptionPane.showMessageDialog(null,
                                "Line " + lineCount + ": Invalid ctrl number received.");
                    }
                    String lastName = container.get(keyList.get(GlobalVar.LAST_NAME_CELL_INDEX_V1));
                    String lastFour = container.get(keyList.get(GlobalVar.LAST4_CELL_INDEX_V1)); // last four
                    // lastName = DB.getSSN(lastName, lastFour);

                    String signOutDate = container.get(keyList.get(GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V1));
                    String signInDate = container.get(keyList.get(GlobalVar.SIGN_IN_DATE_CELL_INDEX_V1));
                    String leaveArea = container.get(keyList.get(GlobalVar.LEAVE_AREA_CELL_INDEX_V1));
                    String leaveType = container.get(keyList.get(GlobalVar.LEAVE_TYPE_CELL_INDEX_V1));

                    //Map<String, String> thisMap = DB.get(thislastName, lastFour);
                    String SSN = DB.getSSN(lastName, lastFour);
                    //System.out.println("xlsx2batchHandler.java" + SSN + "+" + lastName);
                    String first5 = DB.getFirst5(lastName, lastFour);
                    MyDate soDate = new MyDate(signOutDate);
                    MyDate siDate = new MyDate(signInDate);
                    String leaveDays = "---";
                    if (siDate != null && siDate.afterOrEqual(soDate)) {
                        leaveDays = GlobalVar.computeNumOfDays(soDate, siDate);
                    } else {
                        JOptionPane.showMessageDialog(null,
                                "Line " + lineCount + ": How to sign in before sign out?");
                    }

                    if (leaveDays != null) {
                        int leaveMsg = GlobalVar.checkLeaves(ctrlNum, SSN, signOutDate, signInDate, first5,
                                leaves); //add leave into leaves
                        globalCount = GlobalVar.batchGenerator(SSN, first5, lastName, signOutDate, signInDate,
                                leaveType, leaveDays, leaveArea, ctrlNum, leaveMsg, lineCount, globalCount,
                                output, errorList, ADSN);
                    } else {
                        JOptionPane.showMessageDialog(null,
                                "Line " + lineCount + ": Invalid dates are entered!");
                    }
                }
                String msg = "BatchGenerator.java:  The batch file is generated successfully! \n";
                if (!errorList.isEmpty()) {
                    for (String errorMsg : errorList) {
                        msg += errorMsg + "\n";
                    }
                }
                batchFileExists = true;
                JOptionPane.showMessageDialog(null, msg);
                fis.close();
                //                    output.close();
                //                    outputFile.close();
            } else if (numCell == GlobalVar.LEAVE_TITLES_V2.length && DB.isUCFRLoaded()) { // full SSN xlsx
                System.out.println("XLSX2BatchHandler.java: V2, UCFR is loaded.");
                int globalCount = 1;
                while (rowIterator.hasNext()) {
                    //int cellCount = 0;             
                    lineCount++;
                    Row row = rowIterator.next();
                    Iterator<Cell> cellIterator = row.cellIterator();
                    Map<String, String> rowContainer = new HashMap<>(); //store info of each row          
                    rowContainerBuilder(rowContainer, keyList, cellIterator); // update rowContainer                       
                    //    public static final String[] SIGNED_LEAVE_TITLES = {"Ctrl Number", 
                    //            "SSN", "Last Name", "Sign-in Date", "Sign-out Date", "Leave Area",
                    //        "Leave Type", "Num of Days", "First Five","Projected Sign-in Date", "Projected Sign-out Date"};
                    //      make sure the key mataches the name in the header

                    String ctrlNum = GlobalVar
                            .readCtrlNum(rowContainer.get(keyList.get(GlobalVar.CTRL_NUM_CELL_INDEX_V2)));
                    if (ctrlNum == null) {
                        JOptionPane.showMessageDialog(null,
                                "Line " + lineCount + ": Invalid ctrl number received.");
                    }
                    // String lastName = rowContainer.get(keyList.get(GlobalVar.LAST_NAME_CELL_INDEX_V2));
                    String fullSSN = rowContainer.get(keyList.get(GlobalVar.FULL_SSN_CELL_INDEX_V2)); // full ssn
                    String lastName = DB.getLastNamefromSSN(fullSSN);
                    String lastFour = GlobalVar.last4Generator(fullSSN);
                    String signOutDate = rowContainer.get(keyList.get(GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V2));
                    String signInDate = rowContainer.get(keyList.get(GlobalVar.SIGN_IN_DATE_CELL_INDEX_V2));
                    String leaveArea = rowContainer.get(keyList.get(GlobalVar.LEAVE_AREA_CELL_INDEX_V2));
                    String leaveType = rowContainer.get(keyList.get(GlobalVar.LEAVE_TYPE_CELL_INDEX_V2));

                    String first5 = DB.getFirst5(lastName, lastFour);
                    MyDate soDate = new MyDate(signOutDate);
                    MyDate siDate = new MyDate(signInDate);

                    String leaveDays = "---";
                    if (siDate != null && siDate.afterOrEqual(soDate)) {
                        leaveDays = GlobalVar.computeNumOfDays(soDate, siDate);
                    } else {
                        JOptionPane.showMessageDialog(null,
                                "Line " + lineCount + ": How to sign in before sign out?");
                    }

                    int leaveMsg = GlobalVar.checkLeaves(ctrlNum, fullSSN, signOutDate, signInDate, first5,
                            leaves);
                    globalCount = GlobalVar.batchGenerator(fullSSN, first5, lastName, signOutDate, signInDate,
                            leaveType, leaveDays, leaveArea, ctrlNum, leaveMsg, lineCount, globalCount, output,
                            errorList, ADSN);

                }
                String msg = "BatchGenerator.java:  The batch file is generated successfully! \n";

                if (!errorList.isEmpty()) {
                    for (String errorMsg : errorList) {
                        msg += errorMsg + "\n";
                    }
                }
                batchFileExists = true;
                JOptionPane.showMessageDialog(null, msg);
                fis.close();
                //                    output.close(); 
                //                    outputFile.close();
            } else if (numCell == GlobalVar.LEAVE_TITLES_V2.length && !DB.isUCFRLoaded()) {
                System.out.println("XLSX2BatchHandler.java: V2, UCFR is not loaded.");
                int globalCount = 1;
                while (rowIterator.hasNext()) {
                    //int cellCount = 0;             
                    lineCount++;
                    Row row = rowIterator.next();
                    Iterator<Cell> cellIterator = row.cellIterator();
                    Map<String, String> rowContainer = new HashMap<>(); //store info of each row                                       
                    rowContainerBuilder(rowContainer, keyList, cellIterator); // update rowContainer

                    //    public static final String[] SIGNED_LEAVE_TITLES = {"Ctrl Number", 
                    //            "SSN", "Last Name", "Sign-in Date", "Sign-out Date", "Leave Area",
                    //        "Leave Type", "Num of Days", "First Five","Projected Sign-in Date", "Projected Sign-out Date"};
                    //      make sure the key mataches the name in the header

                    String ctrlNum = GlobalVar
                            .readCtrlNum(rowContainer.get(keyList.get(GlobalVar.CTRL_NUM_CELL_INDEX_V2)));
                    //String ctrlNum = GlobalVar.readCtrlNum(rowContainer.get(keyList.get(GlobalVar.CTRL_NUM_CELL_INDEX_V2))); 
                    if (ctrlNum == null) {
                        JOptionPane.showMessageDialog(null,
                                "Line " + lineCount + ": Invalid ctrl number received.");
                    }
                    // String lastName = rowContainer.get(keyList.get(GlobalVar.LAST_NAME_CELL_INDEX_V2));
                    String fullSSN = rowContainer.get(keyList.get(GlobalVar.FULL_SSN_CELL_INDEX_V2)); // full ssn
                    String lastName = GlobalVar.TEMP_DMO_NAME;
                    String signOutDate = rowContainer.get(keyList.get(GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V2));
                    String signInDate = rowContainer.get(keyList.get(GlobalVar.SIGN_IN_DATE_CELL_INDEX_V2));
                    String leaveArea = rowContainer.get(keyList.get(GlobalVar.LEAVE_AREA_CELL_INDEX_V2));
                    String leaveType = rowContainer.get(keyList.get(GlobalVar.LEAVE_TYPE_CELL_INDEX_V2));
                    String first5 = GlobalVar.TEMP_DMO_NAME;
                    MyDate soDate = new MyDate(signOutDate);
                    MyDate siDate = new MyDate(signInDate);
                    String leaveDays = "---";
                    if (siDate != null && siDate.getDay() != null && soDate != null
                            && soDate.getDay() != null) {
                        if (siDate.afterOrEqual(soDate)) {
                            leaveDays = GlobalVar.computeNumOfDays(soDate, siDate);
                        } else {
                            JOptionPane.showMessageDialog(null,
                                    "Line " + lineCount + ": How to sign in before sign out?");
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Line " + lineCount + ": Invalid date entered");
                    }

                    int leaveMsg = GlobalVar.checkLeaves(ctrlNum, fullSSN, signOutDate, signInDate, first5,
                            leaves);

                    // write the leave on the batch file (PrintStream output)
                    globalCount = GlobalVar.batchGenerator(fullSSN, first5, lastName, signOutDate, signInDate,
                            leaveType, leaveDays, leaveArea, ctrlNum, leaveMsg, lineCount, globalCount, output,
                            errorList, ADSN);
                }
                String msg = "BatchGenerator.java:  The batch file is generated successfully! \n";

                if (!errorList.isEmpty()) {
                    for (String errorMsg : errorList) {
                        msg += errorMsg + "\n";
                    }
                }
                batchFileExists = true;
                JOptionPane.showMessageDialog(null, msg);
                fis.close();
            } else if (!DB.isUCFRLoaded()) {

                JOptionPane.showMessageDialog(null,
                        "XLSX2BatchHandler.java: UCFR needs to be loaded to process this type of xlsx.");
            } else {

                JOptionPane.showMessageDialog(null, "XLSX file doesn't contain correct format!");
            }
        } else {
            JOptionPane.showMessageDialog(null, "XLSX file is empty!");
            System.out.println("The xlsx file is empty!");
        }
        // finds the work book in stance for XLSX file
        output.close();
        outputFile.close();
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "XLSX2BatchHandler.java: Xlsx file not found!");
        Logger.getLogger(XLSX2BatchHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:Files.XLSX2BatchHandler.java

public void rowContainerBuilder(Map<String, String> rowContainer, List<String> keyList,
        Iterator<Cell> cellIterator) {
    int keys = 0;
    while (cellIterator.hasNext()) {
        Cell cell = cellIterator.next();
        if (keys == GlobalVar.CTRL_NUM_CELL_INDEX_V2) {
            String value = cell.getStringCellValue();
            rowContainer.put(keyList.get(keys), value);
        } else if (keys == GlobalVar.FULL_SSN_CELL_INDEX_V2) {
            int type = cell.getCellType();
            String fullSSN = null;
            if (type == HSSFCell.CELL_TYPE_STRING) {
                fullSSN = cell.getStringCellValue(); //string type ssn
                fullSSN = fullSSN.replaceAll("-", "");
            } else {
                DataFormatter df = new DataFormatter();
                //SimpleDateFormat fmt = new SimpleDateFormat("yyMMdd");   
                fullSSN = df.formatCellValue(cell); //return ***-**-****
            }/*from   w w  w  .  ja v a2s  .c o m*/
            fullSSN = GlobalVar.fullSSNgenerator(fullSSN);
            rowContainer.put(keyList.get(keys), fullSSN);
        } else if (keys == GlobalVar.SIGN_OUT_DATE_CELL_INDEX_V2
                || keys == GlobalVar.SIGN_IN_DATE_CELL_INDEX_V2) {
            DataFormatter df = new DataFormatter();
            String dateString = df.formatCellValue(cell);
            rowContainer.put(keyList.get(keys), dateString);
        } else if (keys == GlobalVar.LEAVE_AREA_CELL_INDEX_V2) {
            int type = cell.getCellType();
            String value = null;
            if (type == HSSFCell.CELL_TYPE_STRING) {
                value = GlobalVar.getDMOLeaveArea(cell.getStringCellValue());
            } else if (type == HSSFCell.CELL_TYPE_NUMERIC) {
                value = GlobalVar.getDMOLeaveArea(cell.getNumericCellValue()); //read a double and return string
            }
            rowContainer.put(keyList.get(keys), value);
        } else if (keys == GlobalVar.LEAVE_TYPE_CELL_INDEX_V2) {
            String value = GlobalVar.getDMOLeaveType(cell.getStringCellValue());
            rowContainer.put(keyList.get(keys), value);
        }
        keys++;
    }
}

From source file:FilesHandlers.ExcelHandler.java

/**
 * used for getting the content of the selected file
 *
 * @param file The name of the file to display
 * @param sheet The sheet number//from w  ww .ja v a2s  .co  m
 * @return The content of given sheet
 * @throws java.io.FileNotFoundException
 */
public ArrayList<String[]> getFileCtBySheet(String file, int sheet) throws FileNotFoundException, IOException {
    ArrayList<String[]> list = new ArrayList<String[]>();
    ArrayList<String> row = new ArrayList<>();
    File selectedFile = new File(this.workingDirectory.concat(file));
    FileInputStream inputStream = new FileInputStream(selectedFile);

    XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
    Sheet firstSheet = workbook.getSheetAt(sheet);
    Iterator<Row> iterator = firstSheet.iterator();

    while (iterator.hasNext()) {
        Row nextRow = iterator.next();
        Iterator<Cell> cellIterator = nextRow.cellIterator();

        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();

            switch (cell.getCellType()) {
            case Cell.CELL_TYPE_STRING:
                row.add((String) cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                row.add("" + cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                row.add("" + cell.getNumericCellValue());
                break;
            }

        }
        list.add(row.toArray(new String[list.size()]));
        row = new ArrayList<>();
    }

    workbook.close();
    inputStream.close();

    return list;
}

From source file:fll.util.ExcelCellReader.java

License:Open Source License

/**
 * @see fll.util.CellFileReader#readNext()
 *///from ww w  .jav  a 2  s. co  m
@SuppressFBWarnings(value = "PZLA_PREFER_ZERO_LENGTH_ARRAYS", justification = "Return null rather than zero length array so that we know when we hit EFO")
public String[] readNext() throws IOException {
    if (lineNumber >= sheet.getLastRowNum()) {
        return null;
    }

    ++lineNumber;
    final Row row = sheet.getRow(lineNumber);
    if (null == row) {
        return new String[0];
    }

    final List<String> data = new LinkedList<String>();
    for (int cellIdx = 0; cellIdx < row.getLastCellNum(); ++cellIdx) {
        final Cell cell = row.getCell(cellIdx, Row.RETURN_NULL_AND_BLANK);
        if (null == cell) {
            data.add(null);
        } else {
            final String str;
            if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
                final double d = cell.getNumericCellValue();
                // test if a date!
                if (HSSFDateUtil.isCellDateFormatted(cell)) {
                    // make sure to format times like we expect them
                    final Date date = HSSFDateUtil.getJavaDate(d);
                    str = TournamentSchedule.DATE_FORMAT_AM_PM_SS.get().format(date);
                } else {
                    // check for integer
                    if (FP.equals(d, Math.round(d), 1e-10)) {
                        str = String.valueOf((int) d);
                    } else {
                        str = formatter.formatCellValue(cell, formulaEvaluator);
                    }
                }
            } else {
                str = formatter.formatCellValue(cell, formulaEvaluator);
            }
            data.add(str);
        }
    }
    return data.toArray(new String[data.size()]);
}

From source file:fr.sc.crator.internal.storage.CRAStorageHandlerImpl.java

License:Open Source License

private void loadWeek(CRAtor crator, SpreadCRA cra) {
    int currentRow = STARTING_ROW_NUMBER;
    Row row = cra.getSheet().getRow(currentRow);
    Cell codeCell = row.getCell(CODE_CELL_NUMBER);
    String code = codeCell.getStringCellValue();
    while (code != null && !EMPTY_STRING.equals(code)) {
        Cell titleCell = row.getCell(TITLE_CELL_NUMBER);
        String title = titleCell.getStringCellValue();
        Task task = crator.getTask(code);
        if (task == null) {
            task = CratorFactory.eINSTANCE.createTask();
            task.setCode(code);/*from ww w.j  a v  a 2  s  .c o  m*/
            task.setDescription(title);
            crator.getTasks().add(task);
        }
        for (int i = Calendar.MONDAY; i <= Calendar.FRIDAY; i++) {
            Cell loadCell = row.getCell(DAY_CELL_OFFSET + i);
            double load = loadCell.getNumericCellValue();
            if (load > 0) {
                Work work = CratorFactory.eINSTANCE.createWork();
                work.setLoad(load);
                work.setTask(task);
                cra.getWeek().getDay(i).getWorks().add(work);
            }
        }
        currentRow++;
        row = cra.getSheet().getRow(currentRow);
        codeCell = row.getCell(CODE_CELL_NUMBER);
        code = codeCell.getStringCellValue();
    }
}

From source file:fr.unice.i3s.rockflows.experiments.automatictest.ExcelUtils.java

private static void cloneCell(Cell cnew, Cell cold) {

    cnew.setCellType(cold.getCellType());

    switch (cnew.getCellType()) {
    case Cell.CELL_TYPE_BLANK: {
        cnew.setCellValue(cold.getNumericCellValue());
        break;/*from  w w w .  j a  v  a  2s  .co  m*/
    }
    case Cell.CELL_TYPE_STRING: {
        cnew.setCellValue(cold.getStringCellValue());
        break;
    }
    }
}

From source file:Funcionalidad.LeerExcel.java

public boolean leer(File archivo, Contenedor almacenamiento) {
    boolean ok = true;
    try {/*from w  ww  .  j a v a 2  s .c  o m*/
        FileInputStream fs = new FileInputStream(archivo);
        XSSFWorkbook workbook = new XSSFWorkbook(fs);
        for (int i = 0; i < 5; i++) {
            XSSFSheet sheet = null;
            sheet = workbook.getSheetAt(i);
            Iterator<Row> rowIterator = sheet.iterator();
            Row row;
            while (rowIterator.hasNext()) {
                row = rowIterator.next();
                Iterator<Cell> cellIterator = row.cellIterator();
                Cell celda;
                ArrayList<String> nombres = new ArrayList<>();
                ArrayList<Integer> numeros = new ArrayList<>();
                while (cellIterator.hasNext()) {
                    celda = cellIterator.next();
                    switch (celda.getCellType()) {
                    case Cell.CELL_TYPE_STRING:
                        nombres.add(celda.getStringCellValue());
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        Double d = celda.getNumericCellValue();
                        numeros.add(d.intValue());
                        break;
                    }
                }
                switch (i) {
                case 0:
                    almacenamiento.anadirProfesor(
                            new Profesor(nombres.get(0), nombres.get(1), nombres.get(2), numeros.get(0)));
                    break;
                case 1:
                    almacenamiento
                            .anadidTitulacion(new Titulacion(numeros.get(0), nombres.get(0), numeros.get(1)));
                    break;
                case 2:
                    almacenamiento.anadirAsignatura(new Asignatura(nombres.get(0),
                            almacenamiento.getProfesorPorId(numeros.get(0)), numeros.get(1),
                            almacenamiento.getTitulacionPorId(numeros.get(2)), numeros.get(3), numeros.get(4)));
                    break;
                case 3:
                    almacenamiento.anadirAula(new Aula(numeros.get(0), nombres.get(0)));
                    break;
                case 4:
                    almacenamiento.anadirGrupo(new Grupo(numeros.get(0),
                            almacenamiento.getAulaPorId(numeros.get(1)),
                            almacenamiento.getTitulacionPorId(numeros.get(2)), numeros.get(3), nombres.get(0)));
                    break;
                }
            }
        }

    } catch (Exception ex) {
        //Logger.getLogger(LeerExcel.class.getName()).log(Level.SEVERE, null, ex);
        ok = false;
    }
    return ok;
}