Example usage for org.apache.poi.hssf.usermodel HSSFCell toString

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell toString

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCell toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the cell This method returns a simple representation, anything more complex should be in user code, with knowledge of the semantics of the sheet being processed.

Usage

From source file:com.testmax.util.ExcelSheet.java

License:CDDL license

/**
* This method is used to print the cell data to the console.
* @param cellDataList - List of the data's in the spreadsheet.
*///ww w  .  j a va 2 s  . c o  m
@SuppressWarnings("rawtypes")
private void printToConsole(List cellDataList) {
    for (int i = 0; i < cellDataList.size(); i++) {
        List cellTempList = (List) cellDataList.get(i);
        for (int j = 0; j < cellTempList.size(); j++) {
            HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);
            String stringCellValue = hssfCell.toString();
            System.out.print(stringCellValue + "\t");
        }
        System.out.println();
    }
}

From source file:com.testmax.util.ExcelSheet.java

License:CDDL license

public int getColumnIndex(String columnName) {
    List cellColList = null;//  ww  w.j  a  v  a 2s  .  co  m
    try {
        List cellDataList = this.readExcelFile();
        if (cellDataList.size() > 0) {
            cellColList = (List) cellDataList.get(0);
        }
        for (int i = 0; i < cellColList.size(); i++) {
            HSSFCell hssfCol = (HSSFCell) cellColList.get(i);
            String attr = hssfCol.toString();
            if (attr.equals(columnName)) {
                return i;
            }
        }
    } catch (Exception e) {
        WmLog.printMessage("Can not Find Column Name=" + columnName + " for row="
                + (cellColList != null ? cellColList.get(0) : " No Row"));
    }
    return (-1);
}

From source file:com.testmax.util.ExcelSheet.java

License:CDDL license

public int getRowIndexByColumnValue(int colIndex, String columnValue) {
    List cellRowData = null;/*  w ww .  j  a va  2s  .c om*/
    List cellDataList = this.readExcelFile();

    for (int i = 1; i < cellDataList.size(); i++) {

        try {
            cellRowData = (List) cellDataList.get(i);
            HSSFCell hssfCell = (HSSFCell) cellRowData.get(colIndex);
            String value = hssfCell.toString();

            double y = new Double(value);
            int x = new Double(value).intValue();
            if (x == y) {
                value = String.valueOf(x);
            }

            if (value.equals(columnValue)) {
                return i;
            }
        } catch (Exception e) {
            WmLog.printMessage(
                    "Could not Find value for Column Index=" + colIndex + " and column Value=" + columnValue);
        }
    }
    return (-1);
}

From source file:com.testmax.util.ExcelSheet.java

License:CDDL license

public String getXMLDataset() {
    boolean executetest = true;
    List cellColList = null;//from   w  w  w . j av  a2 s  .c o  m
    File xlFile = new File(this.fileName);
    String name = xlFile.getName().substring(0, xlFile.getName().indexOf(".")).trim();
    String xml = "<global name=\"xls\">\n\t<" + name + " description=\"XML data from Xls=" + this.fileName
            + "\">\n";
    List cellDataList = this.readExcelFile();
    if (cellDataList.size() > 0) {
        cellColList = (List) cellDataList.get(0);
    } else {
        return "<dataset></dataset>";
    }
    for (int i = 1; i < cellDataList.size(); i++) {
        executetest = true;
        String data = "\t\t<data ";
        List cellTempList = (List) cellDataList.get(i);
        for (int j = 0; j < cellColList.size(); j++) {
            //get column as attribute
            HSSFCell hssfCol = (HSSFCell) cellColList.get(j);
            String attr = hssfCol.toString();

            //get Value
            HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);
            String value = hssfCell.toString();

            try {
                double y = new Double(value);
                int x = new Double(value).intValue();
                if (x == y) {
                    value = String.valueOf(x);
                }
            } catch (Exception e) {
            }
            //System.out.print(value + "\t");
            data += attr + "=\"" + value + "\" ";
            if (attr.equalsIgnoreCase("run") && value.equalsIgnoreCase("off")) {
                executetest = false;
            }
        }
        if (executetest) {
            xml += data + "/>\n";
        }
        //System.out.println();
    }
    xml += "\t</" + name + ">\n</global>";
    //System.out.print(xml);
    return xml;
}

From source file:com.viettel.vsaadmin.database.DAO.UsersDAO.java

License:Open Source License

public String importStaffFromExcel() throws Exception {
    List customInfo = new ArrayList();//lst users
    Long attachId = Long.parseLong(getRequest().getParameter("attachId"));//get attactId
    VoAttachs att = (VoAttachs) getSession().get("com.viettel.voffice.database.BO.VoAttachs", attachId);//Attachs BO
    if (att == null) {// if att null return error users
        customInfo.add("error");
    } else {//  ww  w.  j a  v  a  2s.c om

        ResourceBundle rb = ResourceBundle.getBundle("config");//get link tuong doi
        String dir = rb.getString("directory");
        String linkFile = att.getAttachPath();
        linkFile = dir + linkFile;
        InputStream myxls = new FileInputStream(linkFile);//get file excel
        //Get the workbook instance for XLS file
        HSSFWorkbook wb = new HSSFWorkbook(myxls);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row;
        //            HSSFRow firstRow = sheet.getRow(1);
        int rowNums = sheet.getLastRowNum();
        //            UsersDAOHE sdhe = new UsersDAOHE();
        SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
        String userError = "";

        for (int i = 1; i <= rowNums; i++) {
            try {
                row = sheet.getRow(i);
                if (row != null) {
                    Users entity = new Users();
                    HSSFCell cellUserName = row.getCell((short) 0);
                    HSSFCell cellFullName = row.getCell((short) 1);
                    HSSFCell cellEmail = row.getCell((short) 2);
                    HSSFCell cellCellPhone = row.getCell((short) 3);
                    HSSFCell cellDeptName = row.getCell((short) 4);
                    HSSFCell cellBusiness = row.getCell((short) 5);
                    HSSFCell cellPosition = row.getCell((short) 6);
                    HSSFCell cellGender = row.getCell((short) 7);
                    HSSFCell cellTelephone = row.getCell((short) 8);
                    HSSFCell cellFax = row.getCell((short) 9);
                    HSSFCell cellDateOfBirth = row.getCell((short) 10);
                    HSSFCell cellBirthPlace = row.getCell((short) 11);
                    HSSFCell cellStaffCode = row.getCell((short) 12);
                    HSSFCell cellIdentityCard = row.getCell((short) 13);
                    HSSFCell cellIssueDateIdent = row.getCell((short) 14);
                    HSSFCell cellIssuePlaceIdent = row.getCell((short) 15);
                    HSSFCell cellDescription = row.getCell((short) 16);
                    //validate input
                    if (cellUserName != null) {
                        entity.setUserName(cellUserName.toString());
                    } else {
                        userError += i + " li Ti khon,";
                        customInfo.add(userError);
                    }

                    if (cellFullName != null) {
                        entity.setFullName(cellFullName.toString());
                    } else {
                        userError += i + " li Tn y ,";
                        customInfo.add(userError);
                    }

                    if (cellEmail.toString() != null && cellEmail.toString().length() > 0) {
                        entity.setEmail(cellEmail.toString());
                    }

                    if (cellCellPhone.toString() != null && cellCellPhone.toString().length() > 0) {
                        entity.setCellphone(cellCellPhone.toString());
                    }
                    //get dept
                    DepartmentDAOHE deptdhe = new DepartmentDAOHE();
                    Department deptBo = deptdhe.findByName(cellDeptName.toString());
                    if (deptBo != null) {
                        entity.setDeptName(deptBo.getDeptName());
                        entity.setDeptId(deptBo.getDeptId());
                    }
                    //get business
                    BusinessDAOHE busdhe = new BusinessDAOHE();
                    Business busbo = busdhe.findByName(cellBusiness.toString());
                    if (busbo != null) {
                        entity.setBusinessId(busbo.getBusinessId());
                        entity.setBusinessName(busbo.getBusinessName());
                    }
                    //get posId
                    PositionDAOHE posdhe = new PositionDAOHE();
                    Position pos = posdhe.findByName(cellPosition.toString());
                    if (pos != null) {
                        entity.setPosId(pos.getPosId());
                    } else {
                        userError += i + " li Chc v,";
                        customInfo.add(userError);
                    }
                    if (cellTelephone != null) {
                        entity.setTelephone(cellTelephone.toString());
                    }
                    if (cellFax != null) {
                        entity.setFax(cellFax.toString());
                    }
                    if (cellBirthPlace != null) {
                        entity.setBirthPlace(cellBirthPlace.toString());
                    }
                    if (cellStaffCode != null) {
                        entity.setStaffCode(cellStaffCode.toString());
                    }
                    if (cellIdentityCard != null) {
                        entity.setIdentityCard(cellIdentityCard.toString());
                    }
                    if (cellIssuePlaceIdent != null) {
                        entity.setIssuePlaceIdent(cellIssuePlaceIdent.toString());
                    }
                    if (cellIssueDateIdent != null && cellIssueDateIdent.toString().length() > 0) {
                        entity.setIssueDateIdent(formatter.parse(cellIssueDateIdent.toString()));
                    }
                    if (cellDateOfBirth != null) {
                        entity.setDateOfBirth(formatter.parse(cellDateOfBirth.toString()));
                    }
                    if (cellDescription != null) {
                        entity.setDescription(cellDescription.toString());
                    }
                    // end validate input
                    String passwordEncrypt = PasswordService.getInstance().encrypt("Attp@123");
                    entity.setPassword(passwordEncrypt);
                    entity.setPasswordchanged(0L);
                    entity.setStatus(1L);
                    //                        entity.setDeptId(Long.parseLong(cellDeptId.toString()));
                    //                        entity.setPosId(Long.parseLong(cellPosId.toString()));
                    //                        entity.setStatus(Long.parseLong(cellStatus.toString()));
                    //                        entity.setGender(Long.parseLong(cellGender.toString()));
                    String gender;
                    if (cellGender == null) {
                        userError += i + " li Gii tnh,";
                        customInfo.add(userError);
                    } else {
                        gender = cellGender.toString().trim().toLowerCase();
                        if (gender.contains("Nam") || gender.contains("man") || gender.contains("male")) {
                            entity.setGender(0L);
                        } else {
                            entity.setGender(1L);
                        }
                    }
                    if (entity != null) {
                        getSession().saveOrUpdate(entity);
                        RoleUser roleUser = new RoleUser();
                        roleUser.setIsActive(1L);
                        roleUser.setIsAdmin(0L);
                        roleUser.setUserId(entity.getUserId());
                        roleUser.setRoleId(323L);
                        roleUser.setRoleUserPK(new RoleUserPK(322, entity.getUserId()));
                        getSession().saveOrUpdate(roleUser);
                        customInfo.add("success");
                    } else {
                        userError += i + ",";
                        customInfo.add(userError);
                    }

                } // end if row != null
            } // end if att != null
            catch (Exception ex) {
                LogUtil.addLog(ex);//binhnt sonar a160901
                userError += i + ",";
                customInfo.add(userError);
                //                    jsonDataGrid.setCustomInfo(customInfo);
                //                    return "gridData";
            }
        } // end loop

    }
    this.jsonDataGrid.setCustomInfo(customInfo);
    return "gridData";
}

From source file:Control.CtrlCredencial.java

/**
 * This method is used to print the cell data to the console.
 *
 * @param cellDataList - List of the data's in the spreadsheet.
 *///w  ww  .j a v  a2  s.  co m
private ArrayList credencialesToArray(List cellDataList) {

    for (int i = 0; i < cellDataList.size(); i++) {
        List cellTempList = (List) cellDataList.get(i);
        // for (int j = 0; j < cellTempList.size(); j++) {
        // Colocar el numero de la columna
        HSSFCell hssfCell = (HSSFCell) cellTempList.get(3);
        String stringCellValue = hssfCell.toString();
        credenciales.add(stringCellValue);
    }
    Iterator<String> it = credenciales.iterator();
    while (it.hasNext()) {
        String elemento = it.next();

    }

    return credenciales;
}

From source file:Controller.importarController.java

/**
 * funo para importar o arquivo de Alunos
 *
 *///from   ww w  . ja va  2 s  .c om
@SuppressWarnings("unchecked")
private void importarAluno(List dataHolder) {

    String erros = "";
    //camea na linha 1 porque a linha 0  cabealho
    int qtdImportado = 0;
    String totalDeLinhas = String.valueOf(dataHolder.size() - 1);

    AlunoDAO aDAO = new AlunoDAO();
    for (int i = 1; i < dataHolder.size(); i++) {
        List linha = (List) dataHolder.get(i);
        Aluno aluno = new Aluno();
        Curso curso = new Curso();
        for (int col = 0; col < linha.size(); col++) {
            HSSFCell myCell = (HSSFCell) linha.get(col);
            myCell.setCellType(Cell.CELL_TYPE_STRING);
            String stringCellValue = myCell.toString().trim();

            switch (col) {
            case 0:
                aluno.setMatricula(stringCellValue.trim());
                break;
            case 1:
                aluno.setNome(stringCellValue.trim());
                break;
            case 2:
                if (!stringCellValue.trim().equalsIgnoreCase("") && stringCellValue.trim() != null) {
                    aluno.setEmail(stringCellValue.trim());
                }
                break;
            case 3:
                if (!stringCellValue.trim().equalsIgnoreCase("") && stringCellValue.trim() != null) {
                    String tel = Functions.formatString(stringCellValue.trim(), "(##) ####-####");
                    aluno.setTelefone(tel);
                }
                break;
            case 4:
                /*saber o curso*/
                if (stringCellValue.equalsIgnoreCase("BCC")
                        || stringCellValue.equalsIgnoreCase("Cincia da Computao - Curriculo Antigo")) {
                    stringCellValue = "Cincia da Computao - Curriculo Antigo";
                } else if (stringCellValue.equalsIgnoreCase("BCC")
                        || stringCellValue.equalsIgnoreCase("Cincia da Computao - Curriculo Novo")) {
                    stringCellValue = "Cincia da Computao - Curriculo Novo";
                } else if (stringCellValue.equalsIgnoreCase("BCC")
                        || stringCellValue.equalsIgnoreCase("Cincia da Computao - Curriculo Antigo")) {
                    stringCellValue = "Cincia da Computao";
                } else if (stringCellValue.equalsIgnoreCase("BSI")
                        || stringCellValue.equalsIgnoreCase("Sistemas de Informao")) {
                    stringCellValue = "Sistemas de Informao";
                }
                CursoDAO cDAO = new CursoDAO();
                try {
                    curso = cDAO.getCursoByNomeCurso(stringCellValue);
                } catch (Exception ex) {
                    FacesContext.getCurrentInstance().addMessage("growlImportaAluno",
                            new FacesMessage(FacesMessage.SEVERITY_WARN, "Curso no encontrado!", ""));
                }
                cDAO.closeSession();

                if (null != curso.getIdcurso()) {
                    aluno.setCursoidcurso(curso);

                    try {
                        Aluno alunoByMatricula = aDAO.getAlunoByMatricula(aluno.getMatricula());
                        if (alunoByMatricula == null) {
                            //insere porque no existe na base
                            boolean inserido = aDAO.insert(aluno);
                            qtdImportado++;

                        } else {
                            String novoErro = "Aluno " + aluno.getNome() + " j existe.";
                            erros = erros + "\n" + novoErro;
                        }
                    } catch (Exception ex) {
                        FacesContext.getCurrentInstance().addMessage("growlImportaAluno", new FacesMessage(
                                FacesMessage.SEVERITY_WARN, "Erro ao importar aluno" + aluno.getNome(), ""));
                    }
                }
                break;
            }
        }
    }

    aDAO.closeSession();
    this.setImportacaoErrosAluno(erros);
    if (qtdImportado > 0) {
        FacesContext.getCurrentInstance().addMessage("growlImportaAluno", new FacesMessage(
                FacesMessage.SEVERITY_INFO,
                "Importao Realizada!\r\n Importado " + String.valueOf(qtdImportado) + " de " + totalDeLinhas,
                ""));
    } else {
        FacesContext.getCurrentInstance().addMessage("growlImportaAluno",
                new FacesMessage(FacesMessage.SEVERITY_WARN, "Importao no realizada!", ""));
    }

}

From source file:Controller.importarController.java

/**
 * funo para importar o arquivo de Professores
 *
 *///  w  w  w  .  j a  va 2  s.  c  om
@SuppressWarnings("unchecked")
private void importarProfessor(List dataHolder) {
    String erros = "";
    //camea na linha 1 porque a linha 0  cabealho
    int qtdImportado = 0;
    String totalDeLinhas = String.valueOf(dataHolder.size() - 1);

    ProfessorDAO pDAO = new ProfessorDAO();
    for (int i = 1; i < dataHolder.size(); i++) {
        List linha = (List) dataHolder.get(i);
        Professor professor = new Professor();
        Perfil perfil = new Perfil();
        for (int col = 0; col < linha.size(); col++) {
            HSSFCell myCell = (HSSFCell) linha.get(col);
            myCell.setCellType(Cell.CELL_TYPE_STRING);
            String stringCellValue = myCell.toString().trim();

            switch (col) {
            case 0:
                professor.setSiape(Integer.parseInt(stringCellValue.trim()));
                break;
            case 1:
                professor.setNome(stringCellValue.trim());
                break;
            case 2:
                professor.setEmail(stringCellValue.trim());
                break;
            case 3:
                if (!stringCellValue.trim().equalsIgnoreCase("") && stringCellValue.trim() != null) {
                    String tel = Functions.formatString(stringCellValue.trim(), "(##) ####-####");
                    professor.setTelefone(tel);
                }
                break;
            case 4:
                if (stringCellValue.equalsIgnoreCase("sim")) {
                    professor.setAtivo(true);
                } else if (stringCellValue.equalsIgnoreCase("no")) {
                    professor.setAtivo(false);
                }
                break;
            case 5:
                PerfilDAO peDAO = new PerfilDAO();
                try {
                    perfil = peDAO.getPerfilByNome(stringCellValue.trim());
                } catch (Exception ex) {
                    FacesContext.getCurrentInstance().addMessage("growlImportacaoProfessor",
                            new FacesMessage(FacesMessage.SEVERITY_WARN, "Perfil no encontrado!", ""));
                }
                peDAO.closeSession();

                if (null != perfil.getNomeperfil()) {
                    professor.setPerfilidperfil(perfil);
                    try {
                        Professor professorBySiape = pDAO.getProfessorBySiape(professor.getSiape());
                        if (professorBySiape == null) {
                            //insere porque no existe na base
                            boolean inserido = pDAO.insert(professor);
                            qtdImportado++;
                        } else {
                            String novoErro = "Professor " + professor.getNome() + " j existe.";
                            erros = erros + "\n" + novoErro;
                        }
                    } catch (Exception ex) {
                        FacesContext.getCurrentInstance().addMessage("growlImportacaoProfessor",
                                new FacesMessage(FacesMessage.SEVERITY_WARN,
                                        "Erro ao importar professor " + professor.getNome(), ""));
                    }
                }
                break;
            }
        }
    }

    pDAO.closeSession();
    this.setImportacaoErrosProfessor(erros);

    if (qtdImportado > 0) {
        FacesContext.getCurrentInstance().addMessage("growlImportacaoProfessor", new FacesMessage(
                FacesMessage.SEVERITY_INFO,
                "Importao Realizada!\r\n Importado " + String.valueOf(qtdImportado) + " de " + totalDeLinhas,
                ""));
    } else {
        FacesContext.getCurrentInstance().addMessage("growlImportacaoProfessor",
                new FacesMessage(FacesMessage.SEVERITY_WARN, "Importao no realizada!", ""));
    }

}

From source file:Controller.importarController.java

/**
 * funo para importar o arquivo de Trabalho
 *
 *//*from  w  w  w  .  ja  va  2s .c  o  m*/
@SuppressWarnings("unchecked")
private void importarTrabalho(List dataHolder) {

    String erros = "";
    //camea na linha 1 porque a linha 0  cabealho
    int qtdImportado = 0;
    String totalDeLinhas = String.valueOf(dataHolder.size() - 1);

    for (int i = 1; i < dataHolder.size(); i++) {
        List linha = (List) dataHolder.get(i);
        Aluno aluno = new Aluno();
        Curso curso = new Curso();
        Trabalho trab = new Trabalho();
        Defesa defesa = new Defesa();
        Assunto assunto = new Assunto();
        Perfil perfil = new Perfil();
        Professor orientador = new Professor();
        Empresa empresa = new Empresa();
        Banca banca = new Banca();
        Bancastatus bancaStatus = new Bancastatus();
        Convidado conv1 = new Convidado();
        Convidado conv2 = new Convidado();
        Trabalhostatus trabStatus = new Trabalhostatus();
        Modalidade modalidade = new Modalidade();
        Estagio estagio = new Estagio();

        //----------------------------------------------------
        //tipo de estgio
        HSSFCell myCellEstagioTipo = (HSSFCell) linha.get(18);
        myCellEstagioTipo.setCellType(Cell.CELL_TYPE_STRING);
        String stringCellEstagioTipo = myCellEstagioTipo.toString().trim();
        //----------------------------------------------------

        //----------------------------------------------------
        //data defesa
        HSSFCell myCellDataDefesa = (HSSFCell) linha.get(12);
        myCellDataDefesa.setCellType(Cell.CELL_TYPE_STRING);
        String stringCellDataDefesa = myCellDataDefesa.toString().trim();
        //----------------------------------------------------

        for (int col = 0; col < linha.size(); col++) {
            HSSFCell myCell = (HSSFCell) linha.get(col);
            myCell.setCellType(Cell.CELL_TYPE_STRING);
            String stringCellValue = myCell.toString().trim();

            switch (col) {
            case 0:
                /*matricula aluno*/
                aluno.setMatricula(stringCellValue);
                break;
            case 1:
                /*nome aluno*/
                aluno.setNome(stringCellValue);
                break;
            case 2:
                /*saber o curso*/
                if (stringCellValue.equalsIgnoreCase("BCC")
                        || stringCellValue.equalsIgnoreCase("Cincia da Computao - Curriculo Antigo")) {
                    stringCellValue = "Cincia da Computao - Curriculo Antigo";
                } else if (stringCellValue.equalsIgnoreCase("BCC")
                        || stringCellValue.equalsIgnoreCase("Cincia da Computao - Curriculo Novo")) {
                    stringCellValue = "Cincia da Computao - Curriculo Novo";
                } else if (stringCellValue.equalsIgnoreCase("BCC")
                        || stringCellValue.equalsIgnoreCase("Cincia da Computao - Curriculo Antigo")) {
                    stringCellValue = "Cincia da Computao";
                } else if (stringCellValue.equalsIgnoreCase("BSI")
                        || stringCellValue.equalsIgnoreCase("Sistemas de Informao")) {
                    stringCellValue = "Sistemas de Informao";
                }

                CursoDAO cDAO = new CursoDAO();
                try {
                    curso = cDAO.getCursoByNomeCurso(stringCellValue);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Curso no encontrado.";
                    erros = erros + "\n" + novoErro;
                }
                cDAO.closeSession();
                AlunoDAO aDAO = new AlunoDAO();
                if (null != curso.getIdcurso()) {
                    aluno.setCursoidcurso(curso);

                    try {
                        Aluno alunoByMatricula = aDAO.getAlunoByMatricula(aluno.getMatricula());
                        if (alunoByMatricula == null) {
                            //insere porque no existe na base
                            boolean inserido = aDAO.insert(aluno);
                        }
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar aluno.";
                        erros = erros + "\n" + novoErro;

                    }
                }
                trab.setAlunomatricula(aluno);
                aDAO.closeSession();
                break;
            case 3:
                /*titulo trabalho*/
                trab.setTitulo(stringCellValue);
                break;
            case 4:
                /*data matricula do trabalho*/
                trab.setDatamatricula(CalendarFormat.getDataISO(stringCellValue));
                /*horas por dia*/
                trab.setQtdhorasdia(CalendarFormat.parseTime("06:00:00"));
                break;
            case 5:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    /*data minima do trabalho*/
                    defesa.setStatusdefesa(true);
                    defesa.setMatriculadatadefesa(trab.getDatamatricula());
                    defesa.setMindatadefesa(CalendarFormat.getDataISO(stringCellValue));
                }
                break;
            case 6:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    /*data maxima do trabalho*/
                    defesa.setMaxdatadefesa(CalendarFormat.getDataISO(stringCellValue));
                } else {
                    /*insere a data maxima como data de finalizao
                     para estagios no obrigatorios*/
                    trab.setDatafinalizacao(CalendarFormat.getDataISO(stringCellValue));
                }
                break;
            case 7:
                /*assunto/area do trabalho*/
                assunto.setNome(stringCellValue);
                AssuntoDAO asDAO = new AssuntoDAO();
                Assunto assuntoByNome = null;
                try {
                    assuntoByNome = asDAO.getAssuntoByNome(stringCellValue);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Erro ao encontrar assunto.";
                    erros = erros + "\n" + novoErro;
                }
                if (assuntoByNome == null) {
                    try {
                        //insere porque no existe na base
                        boolean inserido = asDAO.insert(assunto);
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro salvar assunto.";
                        erros = erros + "\n" + novoErro;
                    }
                } {
                try {
                    assunto = asDAO.getAssuntoByNome(stringCellValue);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Erro ao encontrar assunto.";
                    erros = erros + "\n" + novoErro;
                }
            }
                trab.setAssuntoidassunto(assunto);
                asDAO.closeSession();
                break;
            case 8:
                if (!stringCellValue.equalsIgnoreCase("")) {
                    orientador.setSiape(Integer.parseInt(stringCellValue));
                }
                break;
            case 9:
                PerfilDAO peDAO = new PerfilDAO();
                ProfessorDAO pDAO = new ProfessorDAO();
                Professor professorBySiape = null;

                orientador.setNome(stringCellValue);

                /*1 tentativa de achar o professor*/
                if (orientador.getNome() != null) {
                    try {
                        professorBySiape = pDAO.getProfessorByNome(orientador.getNome());
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar professor.";
                        erros = erros + "\n" + novoErro;
                    }
                }

                /*2 tentativa de achar o professor*/
                if (null == professorBySiape && orientador.getSiape() != null) {
                    try {
                        professorBySiape = pDAO.getProfessorBySiape(orientador.getSiape());
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar professor.";
                        erros = erros + "\n" + novoErro;
                    }
                }

                if (null == professorBySiape && !orientador.getNome().equalsIgnoreCase("")
                        && !orientador.getNome().equalsIgnoreCase("\\0")) {
                    try {
                        perfil = peDAO.getPerfilByNome("Professor");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar perfil.";
                        erros = erros + "\n" + novoErro;
                    }

                    orientador.setPerfilidperfil(perfil);

                    /*dar o maior siape ao novo professor*/
                    int siape = 0;
                    try {
                        siape = pDAO.getMaiorSiape();
                        siape++;
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao retornar siape.";
                        erros = erros + "\n" + novoErro;
                    }
                    orientador.setSiape(siape);
                    orientador.setAtivo(true);
                    try {
                        boolean inserido = pDAO.insert(orientador);
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao inserir orientador.";
                        erros = erros + "\n" + novoErro;
                    }
                } else {
                    orientador = professorBySiape;
                }

                trab.setProfessorsiape(orientador);
                peDAO.closeSession();
                pDAO.closeSession();
                break;
            case 10:
                EmpresaDAO eDAO = new EmpresaDAO();
                empresa.setNome(stringCellValue);
                Empresa empresaByNome = null;
                try {
                    empresaByNome = eDAO.getEmpresaByNome(empresa.getNome());
                } catch (Exception ex) {
                    Logger.getLogger(importarController.class.getName()).log(Level.SEVERE, null, ex);
                }

                if (empresaByNome == null) {
                    try {
                        eDAO.insert(empresa);
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao inserir empresa.";
                        erros = erros + "\n" + novoErro;
                    }
                    try {
                        empresa = eDAO.getEmpresaByNome(empresa.getNome());
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar empresa.";
                        erros = erros + "\n" + novoErro;
                    }
                } else {
                    empresa = empresaByNome;
                }

                trab.setEmpresaidempresa(empresa);
                eDAO.closeSession();
                break;
            case 11:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    banca.setLocalbanca(stringCellValue);
                }
                break;
            case 12:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    banca.setDatabanca(CalendarFormat.getDataISO(stringCellValue));
                    banca.setDatafinalizacao(CalendarFormat.getDataISO(stringCellValue));
                    trab.setDatafinalizacao(CalendarFormat.getDataISO(stringCellValue));
                }
                break;
            case 13:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    banca.setHorario(CalendarFormat.parseTime(stringCellValue));
                }
                break;
            case 14:
                /*status da banca */
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {

                    BancaStatusDAO bsDAO = new BancaStatusDAO();
                    if (stringCellValue.equalsIgnoreCase("Finalizado")
                            || stringCellValue.equalsIgnoreCase("Reprovado")) {
                        try {
                            bancaStatus = bsDAO.getStatusByTipo("Finalizada");
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao encontrar o status da banca";
                            erros = erros + "\n" + novoErro;
                        }
                    } else if (stringCellValue.equalsIgnoreCase("A") || stringCellValue.equalsIgnoreCase("")) {
                        try {
                            bancaStatus = bsDAO.getStatusByTipo("Em andamento");
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao encontrar o status da banca";
                            erros = erros + "\n" + novoErro;
                        }
                    }
                    banca.setStatusidstatus(bancaStatus);
                    bsDAO.closeSession();
                }
                break;
            case 15:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    /*primeiro convidado */
                    PerfilDAO pe1DAO = new PerfilDAO();
                    ProfessorDAO p1DAO = new ProfessorDAO();

                    Professor professorBySiape1 = null;
                    Professor pConvidado1 = new Professor();
                    String nomeConv1 = stringCellValue;

                    /*procura o professor*/
                    try {
                        professorBySiape1 = p1DAO.getProfessorByNome(nomeConv1);
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar professor convidado 1.";
                        erros = erros + "\n" + novoErro;
                    }

                    /*se no encontrar insere */
                    if (null == professorBySiape1 && !nomeConv1.equalsIgnoreCase("")
                            && !nomeConv1.equalsIgnoreCase("\\0")) {
                        try {
                            perfil = pe1DAO.getPerfilByNome("Professor");
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao encontrar perfil.";
                            erros = erros + "\n" + novoErro;
                        }

                        pConvidado1.setPerfilidperfil(perfil);

                        /*dar o maior siape ao novo professor*/
                        int siape = 0;
                        try {
                            siape = p1DAO.getMaiorSiape();
                            siape++;
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao retornar siape.";
                            erros = erros + "\n" + novoErro;
                        }
                        pConvidado1.setSiape(siape);
                        pConvidado1.setNome(nomeConv1);
                        pConvidado1.setAtivo(true);
                        try {
                            boolean inserido = p1DAO.insert(pConvidado1);
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao inserir orientador.";
                            erros = erros + "\n" + novoErro;
                        }
                    } else {
                        pConvidado1 = professorBySiape1;
                    }

                    conv1.setProfessorsiape(pConvidado1);
                    conv1.setConfirmado(true);
                    conv1.setEnviadoemail(true);
                    conv1.setDataconfirmacao(defesa.getMatriculadatadefesa());
                    conv1.setDataconvite(defesa.getMatriculadatadefesa());

                    pe1DAO.closeSession();
                    p1DAO.closeSession();
                }
                break;
            case 16:
                if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                        && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                        && !stringCellDataDefesa.equalsIgnoreCase("")) {
                    /*segundo convidado */
                    PerfilDAO pe2DAO = new PerfilDAO();
                    ProfessorDAO p2DAO = new ProfessorDAO();
                    Professor professorBySiape2 = null;
                    Professor pConvidado2 = new Professor();
                    String nomeConv2 = stringCellValue;

                    /*procura o professor*/
                    try {
                        professorBySiape2 = p2DAO.getProfessorByNome(nomeConv2);
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar professor convidado 1.";
                        erros = erros + "\n" + novoErro;
                    }

                    /*se no encontrar insere */
                    if (null == professorBySiape2 && !nomeConv2.equalsIgnoreCase("")
                            && !nomeConv2.equalsIgnoreCase("\\0")) {
                        try {
                            perfil = pe2DAO.getPerfilByNome("Professor");
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao encontrar perfil.";
                            erros = erros + "\n" + novoErro;
                        }

                        pConvidado2.setPerfilidperfil(perfil);

                        /*dar o maior siape ao novo professor*/
                        int siape = 0;
                        try {
                            siape = p2DAO.getMaiorSiape();
                            siape++;
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao retornar siape.";
                            erros = erros + "\n" + novoErro;
                        }
                        pConvidado2.setSiape(siape);
                        pConvidado2.setNome(nomeConv2);
                        pConvidado2.setAtivo(true);
                        try {
                            boolean inserido = p2DAO.insert(pConvidado2);
                        } catch (Exception ex) {
                            String novoErro = "Linha: " + i + " . Erro ao inserir orientador.";
                            erros = erros + "\n" + novoErro;
                        }
                    } else {
                        pConvidado2 = professorBySiape2;
                    }

                    conv2.setProfessorsiape(pConvidado2);
                    conv2.setConfirmado(true);
                    conv2.setEnviadoemail(true);
                    conv2.setDataconfirmacao(defesa.getMatriculadatadefesa());
                    conv2.setDataconvite(defesa.getMatriculadatadefesa());

                    pe2DAO.closeSession();
                    p2DAO.closeSession();

                }
                break;
            case 17:
                /*status do trabalho*/
                TrabalhoStatusDAO tsDAO = new TrabalhoStatusDAO();

                if (stringCellValue.equalsIgnoreCase("") || stringCellValue.equalsIgnoreCase("A")) {
                    try {
                        trabStatus = tsDAO.getStatusByTipo("Em andamento");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar o status do trabalho.";
                        erros = erros + "\n" + novoErro;
                    }
                } else if (stringCellValue.equalsIgnoreCase("REPROVADO")) {
                    try {
                        trabStatus = tsDAO.getStatusByTipo("Reprovado");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar o status do trabalho.";
                        erros = erros + "\n" + novoErro;
                    }
                } else if (stringCellValue.equalsIgnoreCase("Finalizado")) {
                    try {
                        trabStatus = tsDAO.getStatusByTipo("Finalizado");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar o status do trabalho.";
                        erros = erros + "\n" + novoErro;
                    }
                }
                trab.setStatusidstatus(trabStatus);
                tsDAO.closeSession();
                break;
            case 18:
                /*tipo de estgio*/
                EstagioDAO estDAO = new EstagioDAO();
                ModalidadeDAO mDAO = new ModalidadeDAO();

                if (stringCellValue.equalsIgnoreCase("ESTAGIO_OBRIGATORIO")
                        || stringCellValue.equalsIgnoreCase("ESTAGIO OBRIGATORIO")) {
                    try {
                        modalidade = mDAO.getModalidadeByNome("Estgio");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar a modalidade.";
                        erros = erros + "\n" + novoErro;
                    }

                    try {
                        estagio = estDAO.getEstagioByTipo("Estgio Obrigatrio");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar a modalidade.";
                        erros = erros + "\n" + novoErro;
                    }
                } else if (stringCellValue.equalsIgnoreCase("estgio no obrigatrio")
                        || stringCellValue.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                        || stringCellValue.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")) {
                    try {
                        modalidade = mDAO.getModalidadeByNome("Estgio");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar o estgio.";
                        erros = erros + "\n" + novoErro;
                    }

                    try {
                        estagio = estDAO.getEstagioByTipo("Estgio No Obrigatrio");
                    } catch (Exception ex) {
                        String novoErro = "Linha: " + i + " . Erro ao encontrar o estgio.";
                        erros = erros + "\n" + novoErro;
                    }
                }
                trab.setEstagioidestagio(estagio);
                trab.setModalidadeidmodalidade(modalidade);

                estDAO.closeSession();
                mDAO.closeSession();
                break;
            }
        }

        //---------------------------------------
        TrabalhoDAO tDAO = new TrabalhoDAO();
        List<Trabalho> trabTemp = new ArrayList<>();
        //procurar trabalho se encontrar no importa novamente
        try {
            if (banca.getLocalbanca() != null && !banca.getLocalbanca().equals("")
                    && !banca.getLocalbanca().equals("\\0")) {
                trabTemp = tDAO.getTrabalhosByConvidado(trab.getAlunomatricula(), trab.getEmpresaidempresa(),
                        trab.getTitulo(), trab.getEstagioidestagio().getTipoestagio(),
                        trab.getProfessorsiape().getSiape(), trab.getProfessorsiape().getNome(),
                        trab.getDatamatricula(), banca.getLocalbanca());
            } else {
                trabTemp = tDAO.getTrabalhos(trab.getAlunomatricula(), trab.getEmpresaidempresa(),
                        trab.getTitulo(), trab.getEstagioidestagio().getTipoestagio(),
                        trab.getProfessorsiape().getSiape(), trab.getProfessorsiape().getNome(),
                        trab.getDatamatricula());
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            String novoErro = "Linha: " + i + " . Erro ao encontrar trabalho.";
            erros = erros + "\n" + novoErro;
        }
        if (trabTemp.isEmpty()) {

            //salvar trabalho
            try {
                boolean inserido = tDAO.insert(trab);
                qtdImportado++;
            } catch (Exception ex) {
                String novoErro = "Linha: " + i + " . Erro ao inserir trabalho.";
                erros = erros + "\n" + novoErro;
            }
            tDAO.closeSession();
            //---------------------------------------

            if (!stringCellEstagioTipo.equalsIgnoreCase("estgio no obrigatrio")
                    && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO_NAO_OBRIGATORIO")
                    && !stringCellEstagioTipo.equalsIgnoreCase("ESTAGIO NAO OBRIGATORIO")
                    && !stringCellDataDefesa.equalsIgnoreCase("\\0")
                    && !stringCellDataDefesa.equalsIgnoreCase("")) {
                //---------------------------------------
                //salvar banca
                BancaDAO bDAO = new BancaDAO();
                banca.setTrabalhoidtrabalho(trab);
                try {
                    boolean inserido = bDAO.insert(banca);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Erro ao inserir banca.";
                    erros = erros + "\n" + novoErro;
                }
                bDAO.closeSession();
                //---------------------------------------
                //salvar o convidado 1
                ConvidadoDAO c1DAO = new ConvidadoDAO();
                conv1.setBancaidbanca(banca);
                try {
                    boolean inserido = c1DAO.insert(conv1);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Erro ao inserir convidado 1.";
                    erros = erros + "\n" + novoErro;
                }
                c1DAO.closeSession();
                //---------------------------------------
                //salvar o convidado 2
                ConvidadoDAO c2DAO = new ConvidadoDAO();
                conv2.setBancaidbanca(banca);
                try {
                    boolean inserido = c2DAO.insert(conv2);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Erro ao inserir convidado 2.";
                    erros = erros + "\n" + novoErro;
                }
                c2DAO.closeSession();
                //---------------------------------------
                //salvar defesa
                DefesaDAO dDAO = new DefesaDAO();
                defesa.setTrabalhoidtrabalho(trab);
                try {
                    boolean inserido = dDAO.insert(defesa);
                } catch (Exception ex) {
                    String novoErro = "Linha: " + i + " . Erro ao inserir defesa.";
                    erros = erros + "\n" + novoErro;
                }
                dDAO.closeSession();
                //---------------------------------------
            }
        } else {
            int line = i + 1;
            String novoErro = "Linha: " + line + " . Erro ao salvar. Trabalho j existe na base.";
            erros = erros + "\n" + novoErro;
        }
    }

    this.setImportacaoErrosTrabalho(erros);
    if (qtdImportado > 0) {
        FacesContext.getCurrentInstance().addMessage("growlImportacaoTrabalho", new FacesMessage(
                FacesMessage.SEVERITY_INFO,
                "Importao Realizada!\r\n Importado " + String.valueOf(qtdImportado) + " de " + totalDeLinhas,
                ""));
    } else {
        FacesContext.getCurrentInstance().addMessage("growlImportacaoTrabalho",
                new FacesMessage(FacesMessage.SEVERITY_WARN, "Importao no realizada!", ""));
    }
}

From source file:Creator.TaskManagerPanel.java

/**
 * Reads a file and returns a list of strings which contain all the variable
 * names/*  ww w.ja v a  2  s. c o  m*/
 *
 * @param filename
 */
public void readXFile(String filename) {

    try {

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row;
        HSSFCell cell;

        int rows; // No of rows
        rows = sheet.getPhysicalNumberOfRows();

        int cols = 0; // No of columns
        int tmp = 0;

        int idCol = -1, idName = -1;
        // This trick ensures that we get the data properly even if it doesn't start from first few rows
        for (int i = 0; i < 1; i++) {
            row = sheet.getRow(i);
            if (row != null) {
                tmp = sheet.getRow(i).getPhysicalNumberOfCells();
                if (tmp > cols) {
                    cols = tmp;
                }
            }

            if (!sheet.getRow(i).getCell(0).toString().equals("io_id")) {
                for (int c = 1; c < cols; c++) {
                    if (sheet.getRow(i).getCell(c).equals("io_id")) {
                        idCol = c;
                        break;
                    }
                }
            } else {
                idCol = 0;
            }

            if (!sheet.getRow(i).getCell(1).toString().equals("io_name")) {
                for (int c = 0; c < cols; c++) {
                    if (sheet.getRow(i).getCell(c).equals("io_name")) {
                        idName = c;
                        break;
                    }
                }
            } else {
                idName = 1;
            }

            if (!sheet.getRow(i).getCell(2).toString().equals("io_station_id")) {
                for (int c = 0; c < cols; c++) {
                    if (sheet.getRow(i).getCell(c).equals("io_station_id")) {
                        stationID = (int) sheet.getRow(1).getCell(c).getNumericCellValue();
                        break;
                    }
                }
            } else {
                stationID = (int) sheet.getRow(1).getCell(2).getNumericCellValue();
            }

        }

        if (idName == -1 || idCol == -1) {
            System.out.println("Could not locate io_name or io_id in excel header");
            return;
        }
        if (stationID == -1) {
            System.out.println("Couldnt locate station id");
            return;
        }

        importedIOVariables = new TreeMap<>();
        int io_id;
        String io_name;

        for (int r = 1; r < rows; r++) {
            row = sheet.getRow(r);
            if (row != null) {

                cell = row.getCell(idCol);
                if (cell != null) {
                    io_id = (int) cell.getNumericCellValue();

                    cell = row.getCell(idName);
                    if (cell != null) {
                        io_name = cell.toString().replace("\"", "");
                        // Read both name and id
                        importedIOVariables.put(io_name, io_id);
                    }
                }

            }
        }
        fs.close();
        mf.loadImportedIos(importedIOVariables, 2, stationID);
    } catch (Exception e) {
        System.out.println("Error reading excel file " + e.getMessage());
    }
}