Example usage for org.apache.poi.hssf.usermodel HSSFRow getCell

List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getCell

Introduction

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

Prototype

@Override
public HSSFCell getCell(int cellnum) 

Source Link

Document

Get the hssfcell representing a given column (logical cell) 0-based.

Usage

From source file:guardias.CalendarioExcel.java

private void comprobarDisponibilidadExcel(HSSFRow hssfRow, DiaCalendario diaCalendario, int opcionDisponible,
        String siglaMedico, List<Medico> listadoMedicos) throws ExceptionColumnaDisponibilidad {
    if (hssfRow.getCell(opcionDisponible) == null
            || "".equals(hssfRow.getCell(opcionDisponible).getStringCellValue())) {
        Medico medico = Medico.getMedicoPorSigla(listadoMedicos, siglaMedico);
        diaCalendario.agregarMedicoDisponible(medico);
    } else if (!hssfRow.getCell(opcionDisponible).getStringCellValue().equalsIgnoreCase(CONSTANTE_FIESTA)
            && !hssfRow.getCell(opcionDisponible).getStringCellValue().equalsIgnoreCase(CONSTANTE_CONSULTA)) {
        throw new ExceptionColumnaDisponibilidad();
    }/*from  w  w  w. j a  v a2 s .c  o m*/
}

From source file:guineu.data.parser.impl.GCGCParserXLS.java

License:Open Source License

public void fillData() {
    try {//from   w w  w. j  a va2s  .  c  o  m
        book = this.openExcel(DatasetName);
        HSSFSheet sheet;
        try {
            sheet = book.getSheet(sheetName);
        } catch (Exception exception) {
            sheet = book.getSheetAt(0);
        }

        int initRow = this.getRowInit(sheet);

        if (initRow > -1) {
            numberRows = this.getNumberRows(initRow, sheet);
            HSSFRow row = sheet.getRow(initRow);

            for (int i = 0; i < row.getLastCellNum(); i++) {
                HSSFCell cell = row.getCell(i);
                this.head.add(cell.toString());
            }
            this.readMetabolites(initRow + 1, numberRows, sheet);

            this.setExperimentsName(head);
        } else {
            this.dataset = null;
        }
    } catch (IOException ex) {
        Logger.getLogger(GCGCParserXLS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:guineu.data.parser.impl.GCGCParserXLS.java

License:Open Source License

/**
 * Reads lipid information of one row./*from   www.jav  a  2  s.c  om*/
 * @param row
 * @param numberCols
 * @return
 */
public void readRow(HSSFRow row) {
    HSSFCell cell;
    SimplePeakListRowGCGC metabolite = new SimplePeakListRowGCGC();
    for (int i = 0; i < row.getLastCellNum(); i++) {
        try {
            String title = head.get(i);
            if (title == null) {
                continue;
            }
            cell = row.getCell(i);
            boolean isfound = false;

            for (GCGCColumnName field : GCGCColumnName.values()) {
                if (title.matches(field.getRegularExpression())) {
                    metabolite.setVar(field.getSetFunctionName(),
                            this.getType(cell.toString(), field.getType()));
                    isfound = true;
                    break;
                }
            }

            if (!isfound) {
                try {
                    metabolite.setPeak(title, cell.getNumericCellValue());
                } catch (Exception e) {
                    metabolite.setPeak(title, 0.0);
                }
            }

            if (metabolite.getName() == null) {
                metabolite.setName("unknown");
            }
        } catch (Exception exception) {
            //exception.printStackTrace();
        }
    }
    this.dataset.addRow(metabolite);
}

From source file:guineu.data.parser.impl.GCGCParserXLS.java

License:Open Source License

/**
 *
 * @param sheet/*w ww  .j  a  v  a  2  s .  c  o m*/
 * @return number of row which it starts to read the excel file.
 */
public int getRowInit(HSSFSheet sheet) {

    Iterator rowIt = sheet.rowIterator();
    int num = -1;

    while (rowIt.hasNext()) {
        HSSFRow row = (HSSFRow) rowIt.next();
        HSSFCell cell = row.getCell(0);

        if (cell != null) {
            for (GCGCColumnName field : GCGCColumnName.values()) {
                if (cell.toString().matches(field.getRegularExpression())) {
                    num = row.getRowNum();
                    break;
                }
            }
        }
    }

    return num;
}

From source file:guineu.data.parser.impl.LCMSParserXLS.java

License:Open Source License

public void fillData() {
    try {/*  www  .ja  va 2s  .  c om*/
        book = this.openExcel(DatasetName);
        HSSFSheet sheet;
        try {
            sheet = book.getSheet(sheetName);
        } catch (Exception exception) {
            sheet = book.getSheetAt(0);
        }

        int initRow = this.getRowInit(sheet);

        if (initRow > -1) {
            numberRows = this.getNumberRows(initRow, sheet);
            HSSFRow row = sheet.getRow(initRow);

            for (int i = 0; i < row.getLastCellNum(); i++) {
                HSSFCell cell = row.getCell((short) i);
                this.head.add(cell.toString());
            }
            this.readLipids(initRow + 1, numberRows, sheet);

            this.setExperimentsName(head);
        } else {
            this.dataset = null;
        }
    } catch (IOException ex) {
        Logger.getLogger(LCMSParserXLS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:guineu.data.parser.impl.LCMSParserXLS.java

License:Open Source License

/**
 * Reads lipid information of one row.//w w  w.  j  av a 2s . c  om
 * @param row
 * @param numberCols
 * @return
 */
public void readRow(HSSFRow row) {
    HSSFCell cell;
    SimplePeakListRowLCMS lipid = new SimplePeakListRowLCMS();
    for (int i = 0; i < row.getLastCellNum(); i++) {
        try {
            String title = head.get(i);
            if (title == null) {
                continue;
            }
            cell = row.getCell((short) i);
            boolean isfound = false;
            for (LCMSColumnName field : LCMSColumnName.values()) {
                if (title.matches(field.getRegularExpression())) {
                    if (field == LCMSColumnName.RT) {
                        double rt = cell.getNumericCellValue();
                        if (rt < 20) {
                            rt *= 60;
                            lipid.setVar(field.getSetFunctionName(), rt);
                        } else {
                            lipid.setVar(field.getSetFunctionName(), cell.getNumericCellValue());
                        }
                    } else {
                        lipid.setVar(field.getSetFunctionName(),
                                this.getType(cell.toString(), field.getType()));
                    }
                    isfound = true;
                    break;
                }
            }

            if (!isfound) {
                try {
                    lipid.setPeak(title, cell.getNumericCellValue());
                } catch (Exception e) {
                    if (cell.toString().matches(".*null.*|.*NA.*|.*N/A.*")) {
                        lipid.setPeak(title, 0.0);
                    } else if (cell.toString() != null) {
                        lipid.setPeak(title, cell.toString());
                    }
                }
            }

            if (i == 0 && (cell.getCellStyle().getFillForegroundColor() == 13)) {
                lipid.setStandard(1);
            }
            int DataType = this.v_type(book, row, cell);
            if (DataType == 0) {
                lipid.setControl(false);
                lipid.setName("z-non valid");
            } else {
                lipid.setControl(true);
            }

            if (lipid.getName() == null) {
                lipid.setName("unknown");
            }
            lipid.setLipidClass(String.valueOf(this.LipidClassLib.get_class(lipid.getName())));
        } catch (Exception exception) {
            //exception.printStackTrace();
        }
    }
    this.dataset.addRow(lipid);
}

From source file:guineu.data.parser.impl.LCMSParserXLS.java

License:Open Source License

/**
 *
 * @param sheet/* ww  w .j  a va2  s .c  o  m*/
 * @return number of row which it starts to read the excel file.
 */
public int getRowInit(HSSFSheet sheet) {

    Iterator rowIt = sheet.rowIterator();
    int num = -1;

    while (rowIt.hasNext()) {
        HSSFRow row = (HSSFRow) rowIt.next();
        HSSFCell cell = row.getCell((short) 0);

        if (cell != null) {
            for (LCMSColumnName field : LCMSColumnName.values()) {
                if (cell.toString().matches(field.getRegularExpression())) {
                    num = row.getRowNum();
                    break;
                }
            }
        }
    }

    return num;
}

From source file:guineu.data.parser.impl.ParserXLS.java

License:Open Source License

public int getNumberRows(int init, HSSFSheet sheet) {
    Iterator rowIt = sheet.rowIterator();
    int num = 0;/*from   w  ww  .  j a v  a 2s .  co  m*/

    while (rowIt.hasNext()) {
        HSSFRow row = (HSSFRow) rowIt.next();
        HSSFCell cell;
        cell = row.getCell(0);
        if ((cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) && row.getRowNum() > init) {
            break;
        }
        num = row.getRowNum();
    }
    return num - init;
}

From source file:guineu.database.intro.impl.WriteFile.java

License:Open Source License

/**
 * Write data in a cell of the excel file.
 *
 * @param row Cell row// w  w w . j  a  va 2  s  .  co  m
 * @param Index Cell column
 * @param data data to be writen into the cell
 */
private void setCell(HSSFRow row, int Index, Object data, HSSFColor color) {
    HSSFCell cell = row.getCell(Index);
    if (cell == null) {
        cell = row.createCell(Index);
    }
    if (data.getClass().toString().contains("String") || data.getClass().toString().contains("Boolean")) {
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(String.valueOf(data));
    } else if (data.getClass().toString().contains("Double")) {
        cell.setCellValue((Double) data);
    } else if (data.getClass().toString().contains("Integer")) {
        cell.setCellValue((Integer) data);
    }
    if (color != null) {
        HSSFCellStyle style1 = wb.createCellStyle();
        style1.setFillForegroundColor(color.getIndex());
        style1.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        for (HSSFCellStyle style : styles) {
            if (style.getFillForegroundColor() == style1.getFillForegroundColor()) {
                style1 = style;
            }
        }
        if (!styles.contains(style1)) {
            this.styles.add(style1);
        }
        cell.setCellStyle(style1);
    } else {
    }
}

From source file:guineu.modules.configuration.parameters.ParameterDialog.java

License:Open Source License

public void readRows(HSSFSheet sheet) {
    try {//  w  w w .  j  ava  2 s .c  o m
        Iterator rowIt = sheet.rowIterator();
        HSSFRow row = (HSSFRow) rowIt.next();

        for (int i = 1; i < row.getLastCellNum(); i++) {
            HSSFCell cell = row.getCell(i);
            model.addColumn(cell.toString());
        }
        ((ParameterDataModel) model).fireTableStructureChanged();
        table.getColumnModel().getColumn(0).setMinWidth(300);
        int rowIndex = -1;
        while (rowIt.hasNext()) {
            row = (HSSFRow) rowIt.next();
            HSSFCell cell;
            cell = row.getCell(0);
            for (int e = 0; e < model.getRowCount(); e++) {
                String sampleName = model.getValueAt(e, 0);
                if (sampleName.equals(cell.toString())) {
                    rowIndex = e;
                }
            }
            for (int i = 1; i < row.getLastCellNum(); i++) {
                cell = row.getCell(i);
                model.setValueAt(cell.toString(), rowIndex, i);
            }
        }
        ((ParameterDataModel) model).addParameters(dataset);
        ((ParameterDataModel) model).fireTableDataChanged();
    } catch (Exception e) {
        e.printStackTrace();
    }
}