Example usage for org.apache.poi.ss.usermodel Row getRowNum

List of usage examples for org.apache.poi.ss.usermodel Row getRowNum

Introduction

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

Prototype

int getRowNum();

Source Link

Document

Get row number this row represents

Usage

From source file:org.cgiar.ccafs.marlo.utils.ReadExcelFile.java

License:Open Source License

public List<Row> searchForEmptyRows(Sheet sheet) {
    // Decide which rows to process
    List<Row> notEmptyRows = new ArrayList<>();
    Row firstRow = sheet.getRow(10);
    if (firstRow != null) {
        int rowStart = firstRow.getRowNum();
        int rowEnd = sheet.getLastRowNum();

        for (int rowNum = rowStart; rowNum <= rowEnd; rowNum++) {
            Row r = sheet.getRow(rowNum);
            if (r != null) {
                notEmptyRows.add(r);/*  w w  w  .jav a2  s .c o m*/
                continue;
            }

        }
    }

    return notEmptyRows;
}

From source file:org.codelabor.example.crud.emp.web.controller.EmpController.java

License:Apache License

private List<EmpDto> fileToDtoList(MultipartFile file, List<String> failureMessages)
        throws IllegalArgumentException, InvalidFormatException, IOException { // NOPMD
    // by/* w  ww.  j  a va 2 s.c om*/
    // "SHIN Sang-jae"

    Workbook wb = WorkbookFactory.create(file.getInputStream());
    int numberOfSheets = wb.getNumberOfSheets();
    logger.debug("numberOfSheets: {}", numberOfSheets);

    // prepare model
    List<EmpDto> empDtoList = new ArrayList<EmpDto>();

    // set effective position
    int effectiveFirstSheetIndex = 0;
    int effectiveLastSheetIndex = numberOfSheets - 1;

    // traverse sheet
    StringBuilder sb = new StringBuilder();
    for (int i = effectiveFirstSheetIndex; i <= effectiveLastSheetIndex; i++) {
        Sheet sheet = wb.getSheetAt(i);
        String sheetName = sheet.getSheetName();
        logger.debug("sheetName: {}", sheetName);
        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();
        logger.debug("firstRowNum: {},  lastRowNum: {}", firstRowNum, lastRowNum);

        // set effective position
        int effectiveFirstRowIndex = 1; // header row: 0
        int effectiveLastRowIndex = lastRowNum;

        // traverse row
        for (int j = effectiveFirstRowIndex; j <= effectiveLastRowIndex; j++) {
            // prepare model
            EmpDto empDto = new EmpDto(); // NOPMD by "SHIN Sang-jae"

            Row row = sheet.getRow(j);
            int rowNum = row.getRowNum();
            int firstCellNum = row.getFirstCellNum();
            int lastCellNum = row.getLastCellNum();
            logger.debug("rowNum: {}, firstCellNum: {},  lastCellNum: {}", rowNum, firstCellNum, lastCellNum);

            // set effective position
            int effectiveFirstCellIndex = firstCellNum;
            int effectiveLastCellIndex = lastCellNum - 1;

            // traverse cell
            for (int k = effectiveFirstCellIndex; k <= effectiveLastCellIndex; k++) {
                Cell cell = row.getCell(k);
                if (cell != null) {
                    int rowIndex = cell.getRowIndex();
                    int columnIndex = cell.getColumnIndex();
                    CellReference cellRef = new CellReference(rowIndex, columnIndex); // NOPMD by "SHIN Sang-jae"

                    logger.debug("cellRef: {}, rowIndex: {}, columnIndex: {}", cellRef, rowIndex, columnIndex);
                    // populate dto
                    switch (k) {
                    case 0: // EMPNO
                        empDto.setEmpNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 1: // ENAME
                        empDto.setEname(cell.getRichStringCellValue().toString());
                        break;
                    case 2: // JOB
                        empDto.setJob(cell.getRichStringCellValue().toString());
                        break;
                    case 3: // MGR
                        empDto.setMgr(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 4: // HIREDATE
                        empDto.setHireDate(cell.getDateCellValue());
                        break;
                    case 5: // SAL
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setSal(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 6: // COMM
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setComm(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 7: // DEPTNO
                        empDto.setDeptNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    default:
                        break;
                    }
                }
            }
            logger.debug("empDto: {}", empDto);

            // validate
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            Set<ConstraintViolation<EmpDto>> violations = validator.validate(empDto);

            if (violations.isEmpty()) {
                // do all or nothing
                empDtoList.add(empDto);
            } else {
                // add failure message
                sb.setLength(0); // init StringBuilder for reuse
                for (ConstraintViolation<EmpDto> violation : violations) {
                    String propertyPath = violation.getPropertyPath().toString();
                    String message = violation.getMessage();
                    sb.append(message);
                    sb.append(" (row: ").append(j).append(", property: ").append(propertyPath).append(')');
                    failureMessages.add(sb.toString());
                    logger.error(sb.toString());
                    sb.setLength(0);
                }
            }
        }
    }
    return empDtoList;
}

From source file:org.codelabor.example.crud.emp.web.controller.EmpController.java

License:Apache License

private List<EmpDto> fileToDtoList(Part file, List<String> failureMessages)
        throws IllegalArgumentException, InvalidFormatException, IOException { // NOPMD
    // by//  w ww. j a v a2  s.c o m
    // "SHIN Sang-jae"

    Workbook wb = WorkbookFactory.create(file.getInputStream());
    int numberOfSheets = wb.getNumberOfSheets();
    logger.debug("numberOfSheets: {}", numberOfSheets);

    // prepare model
    List<EmpDto> empDtoList = new ArrayList<EmpDto>();

    // set effective position
    int effectiveFirstSheetIndex = 0;
    int effectiveLastSheetIndex = numberOfSheets - 1;

    // traverse sheet
    StringBuilder sb = new StringBuilder();
    for (int i = effectiveFirstSheetIndex; i <= effectiveLastSheetIndex; i++) {
        Sheet sheet = wb.getSheetAt(i);
        String sheetName = sheet.getSheetName();
        logger.debug("sheetName: {}", sheetName);
        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();
        logger.debug("firstRowNum: {},  lastRowNum: {}", firstRowNum, lastRowNum);

        // set effective position
        int effectiveFirstRowIndex = 1; // header row: 0
        int effectiveLastRowIndex = lastRowNum;

        // traverse row
        for (int j = effectiveFirstRowIndex; j <= effectiveLastRowIndex; j++) {
            // prepare model
            EmpDto empDto = new EmpDto(); // NOPMD by "SHIN Sang-jae"

            Row row = sheet.getRow(j);
            int rowNum = row.getRowNum();
            int firstCellNum = row.getFirstCellNum();
            int lastCellNum = row.getLastCellNum();
            logger.debug("rowNum: {}, firstCellNum: {},  lastCellNum: {}", rowNum, firstCellNum, lastCellNum);

            // set effective position
            int effectiveFirstCellIndex = firstCellNum;
            int effectiveLastCellIndex = lastCellNum - 1;

            // traverse cell
            for (int k = effectiveFirstCellIndex; k <= effectiveLastCellIndex; k++) {
                Cell cell = row.getCell(k);
                if (cell != null) {
                    int rowIndex = cell.getRowIndex();
                    int columnIndex = cell.getColumnIndex();
                    CellReference cellRef = new CellReference(rowIndex, columnIndex); // NOPMD by "SHIN Sang-jae"

                    logger.debug("cellRef: {}, rowIndex: {}, columnIndex: {}", cellRef, rowIndex, columnIndex);
                    // populate dto
                    switch (k) {
                    case 0: // EMPNO
                        empDto.setEmpNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 1: // ENAME
                        empDto.setEname(cell.getRichStringCellValue().toString());
                        break;
                    case 2: // JOB
                        empDto.setJob(cell.getRichStringCellValue().toString());
                        break;
                    case 3: // MGR
                        empDto.setMgr(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 4: // HIREDATE
                        empDto.setHireDate(cell.getDateCellValue());
                        break;
                    case 5: // SAL
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setSal(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 6: // COMM
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setComm(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 7: // DEPTNO
                        empDto.setDeptNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    default:
                        break;
                    }
                }
            }
            logger.debug("empDto: {}", empDto);

            // validate
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            Set<ConstraintViolation<EmpDto>> violations = validator.validate(empDto);

            if (violations.isEmpty()) {
                // do all or nothing
                empDtoList.add(empDto);
            } else {
                // add failure message
                sb.setLength(0); // init StringBuilder for reuse
                for (ConstraintViolation<EmpDto> violation : violations) {
                    String propertyPath = violation.getPropertyPath().toString();
                    String message = violation.getMessage();
                    sb.append(message);
                    sb.append(" (row: ").append(j).append(", property: ").append(propertyPath).append(')');
                    failureMessages.add(sb.toString());
                    logger.error(sb.toString());
                    sb.setLength(0);
                }
            }
        }
    }
    return empDtoList;
}

From source file:org.codelabor.example.emp.web.controller.EmpController.java

License:Apache License

private List<EmpDto> fileToDtoList(MultipartFile file, List<String> failureMessages)
        throws IllegalArgumentException, InvalidFormatException, IOException { // NOPMD by "SHIN Sang-jae"

    Workbook wb = WorkbookFactory.create(file.getInputStream());
    int numberOfSheets = wb.getNumberOfSheets();
    logger.debug("numberOfSheets: {}", numberOfSheets);

    // prepare model
    List<EmpDto> empDtoList = new ArrayList<EmpDto>();

    // set effective position
    int effectiveFirstSheetIndex = 0;
    int effectiveLastSheetIndex = numberOfSheets - 1;

    // traverse sheet
    StringBuilder sb = new StringBuilder();
    for (int i = effectiveFirstSheetIndex; i <= effectiveLastSheetIndex; i++) {
        Sheet sheet = wb.getSheetAt(i);/*from w w w  . ja v  a2  s.c  o m*/
        String sheetName = sheet.getSheetName();
        logger.debug("sheetName: {}", sheetName);
        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();
        logger.debug("firstRowNum: {},  lastRowNum: {}", firstRowNum, lastRowNum);

        // set effective position
        int effectiveFirstRowIndex = 1; // header row: 0
        int effectiveLastRowIndex = lastRowNum;

        // traverse row
        for (int j = effectiveFirstRowIndex; j <= effectiveLastRowIndex; j++) {
            // prepare model
            EmpDto empDto = new EmpDto(); // NOPMD by "SHIN Sang-jae"

            Row row = sheet.getRow(j);
            int rowNum = row.getRowNum();
            int firstCellNum = row.getFirstCellNum();
            int lastCellNum = row.getLastCellNum();
            logger.debug("rowNum: {}, firstCellNum: {},  lastCellNum: {}", rowNum, firstCellNum, lastCellNum);

            // set effective position
            int effectiveFirstCellIndex = firstCellNum;
            int effectiveLastCellIndex = lastCellNum - 1;

            // traverse cell
            for (int k = effectiveFirstCellIndex; k <= effectiveLastCellIndex; k++) {
                Cell cell = row.getCell(k);
                if (cell != null) {
                    int rowIndex = cell.getRowIndex();
                    int columnIndex = cell.getColumnIndex();
                    CellReference cellRef = new CellReference(rowIndex, columnIndex); // NOPMD by "SHIN Sang-jae"

                    logger.debug("cellRef: {}, rowIndex: {}, columnIndex: {}", cellRef, rowIndex, columnIndex);
                    // populate dto
                    switch (k) {
                    case 0: // EMPNO
                        empDto.setEmpNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 1: // ENAME
                        empDto.setEname(cell.getRichStringCellValue().toString());
                        break;
                    case 2: // JOB
                        empDto.setJob(cell.getRichStringCellValue().toString());
                        break;
                    case 3: // MGR
                        empDto.setMgr(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 4: // HIREDATE
                        empDto.setHireDate(cell.getDateCellValue());
                        break;
                    case 5: // SAL
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setSal(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 6: // COMM
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setComm(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 7: // DEPTNO
                        empDto.setDeptNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    default:
                        break;
                    }
                }
            }
            logger.debug("empDto: {}", empDto);

            // validate
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            Set<ConstraintViolation<EmpDto>> violations = validator.validate(empDto);

            if (violations.isEmpty()) {
                // do all or nothing
                empDtoList.add(empDto);
            } else {
                // add failure message
                sb.setLength(0); // init StringBuilder for reuse
                for (ConstraintViolation<EmpDto> violation : violations) {
                    String propertyPath = violation.getPropertyPath().toString();
                    String message = violation.getMessage();
                    sb.append(message);
                    sb.append(" (row: ").append(j).append(", property: ").append(propertyPath).append(')');
                    failureMessages.add(sb.toString());
                    logger.error(sb.toString());
                    sb.setLength(0);
                }
            }
        }
    }
    return empDtoList;
}

From source file:org.codelabor.example.emp.web.controller.EmpController.java

License:Apache License

private List<EmpDto> fileToDtoList(Part file, List<String> failureMessages)
        throws IllegalArgumentException, InvalidFormatException, IOException { // NOPMD by "SHIN Sang-jae"

    Workbook wb = WorkbookFactory.create(file.getInputStream());
    int numberOfSheets = wb.getNumberOfSheets();
    logger.debug("numberOfSheets: {}", numberOfSheets);

    // prepare model
    List<EmpDto> empDtoList = new ArrayList<EmpDto>();

    // set effective position
    int effectiveFirstSheetIndex = 0;
    int effectiveLastSheetIndex = numberOfSheets - 1;

    // traverse sheet
    StringBuilder sb = new StringBuilder();
    for (int i = effectiveFirstSheetIndex; i <= effectiveLastSheetIndex; i++) {
        Sheet sheet = wb.getSheetAt(i);//from   ww w  .  java 2  s  . c o m
        String sheetName = sheet.getSheetName();
        logger.debug("sheetName: {}", sheetName);
        int firstRowNum = sheet.getFirstRowNum();
        int lastRowNum = sheet.getLastRowNum();
        logger.debug("firstRowNum: {},  lastRowNum: {}", firstRowNum, lastRowNum);

        // set effective position
        int effectiveFirstRowIndex = 1; // header row: 0
        int effectiveLastRowIndex = lastRowNum;

        // traverse row
        for (int j = effectiveFirstRowIndex; j <= effectiveLastRowIndex; j++) {
            // prepare model
            EmpDto empDto = new EmpDto(); // NOPMD by "SHIN Sang-jae"

            Row row = sheet.getRow(j);
            int rowNum = row.getRowNum();
            int firstCellNum = row.getFirstCellNum();
            int lastCellNum = row.getLastCellNum();
            logger.debug("rowNum: {}, firstCellNum: {},  lastCellNum: {}", rowNum, firstCellNum, lastCellNum);

            // set effective position
            int effectiveFirstCellIndex = firstCellNum;
            int effectiveLastCellIndex = lastCellNum - 1;

            // traverse cell
            for (int k = effectiveFirstCellIndex; k <= effectiveLastCellIndex; k++) {
                Cell cell = row.getCell(k);
                if (cell != null) {
                    int rowIndex = cell.getRowIndex();
                    int columnIndex = cell.getColumnIndex();
                    CellReference cellRef = new CellReference(rowIndex, columnIndex); // NOPMD by "SHIN Sang-jae"

                    logger.debug("cellRef: {}, rowIndex: {}, columnIndex: {}", cellRef, rowIndex, columnIndex);
                    // populate dto
                    switch (k) {
                    case 0: // EMPNO
                        empDto.setEmpNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 1: // ENAME
                        empDto.setEname(cell.getRichStringCellValue().toString());
                        break;
                    case 2: // JOB
                        empDto.setJob(cell.getRichStringCellValue().toString());
                        break;
                    case 3: // MGR
                        empDto.setMgr(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    case 4: // HIREDATE
                        empDto.setHireDate(cell.getDateCellValue());
                        break;
                    case 5: // SAL
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setSal(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 6: // COMM
                        // http://stackoverflow.com/questions/12395281/convert-double-to-bigdecimal-and-set-bigdecimal-precision
                        empDto.setComm(BigDecimal.valueOf(cell.getNumericCellValue()));
                        break;
                    case 7: // DEPTNO
                        empDto.setDeptNo(((Double) cell.getNumericCellValue()).intValue());
                        break;
                    default:
                        break;
                    }
                }
            }
            logger.debug("empDto: {}", empDto);

            // validate
            Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
            Set<ConstraintViolation<EmpDto>> violations = validator.validate(empDto);

            if (violations.isEmpty()) {
                // do all or nothing
                empDtoList.add(empDto);
            } else {
                // add failure message
                sb.setLength(0); // init StringBuilder for reuse
                for (ConstraintViolation<EmpDto> violation : violations) {
                    String propertyPath = violation.getPropertyPath().toString();
                    String message = violation.getMessage();
                    sb.append(message);
                    sb.append(" (row: ").append(j).append(", property: ").append(propertyPath).append(')');
                    failureMessages.add(sb.toString());
                    logger.error(sb.toString());
                    sb.setLength(0);
                }
            }
        }
    }
    return empDtoList;
}

From source file:org.codice.imaging.nitf.registryparser.TreMetadataSheetHandler.java

License:Open Source License

public final void process() throws IOException, XMLStreamException {
    for (Row row : metadataSheet) {
        if (row.getRowNum() == 0) {
            continue;
        }//from  w  w w .  j a va2s . c  om
        handleOneRow(row);
    }
    for (SimpleFieldLookupHandler handler : simpleHandlers) {
        handler.serialise();
    }
    for (SensorFieldLookupHandler handler : sensorHandlers) {
        handler.serialise();
    }
}

From source file:org.codice.imaging.nitf.registryparser.TreMetadataSheetHandler.java

License:Open Source License

private void handleOneRow(Row row) {
    String treName = row.getCell(TRE_COLUMN).toString();
    String fieldName = row.getCell(FIELD_NAME_COLUMN).toString();
    String fieldValue = row.getCell(VALUE_COLUMN).toString();
    String sensor = row.getCell(SENSOR_COLUMN).toString();
    String description = row.getCell(DESCRIPTION_COLUMN).toString();
    if (sensor.equals("N/A")) {
        handleSimpleRow(treName, fieldName, fieldValue, description, row.getRowNum());
    } else {// w  w w. j ava 2  s.c o  m
        handleSensorRow(sensor, treName, fieldName, fieldValue, description, row.getRowNum());
    }
}

From source file:org.dash.valid.freq.HLAFrequenciesLoader.java

License:Open Source License

private List<DisequilibriumElement> loadNMDPLinkageReferenceData(String filename, Locus[] locusPositions)
        throws IOException, InvalidFormatException {
    List<DisequilibriumElement> disequilibriumElements = new ArrayList<DisequilibriumElement>();

    // Finds the workbook instance for XLSX file
    InputStream inStream = HLAFrequenciesLoader.class.getClassLoader().getResourceAsStream(filename);

    if (inStream == null) {
        throw new FileNotFoundException();
    }//from  w w w  .  ja v  a2 s .co m

    Workbook workbook = WorkbookFactory.create(inStream);

    // Return first sheet from the XLSX workbook
    Sheet mySheet = workbook.getSheetAt(0);

    // Get iterator to all the rows in current sheet
    Iterator<Row> rowIterator = mySheet.iterator();

    int firstRow = mySheet.getFirstRowNum();

    List<String> raceHeaders = null;

    // Traversing over each row of XLSX file
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();

        if (row.getRowNum() == firstRow) {
            raceHeaders = readHeaderElementsByRace(row);
        } else {
            disequilibriumElements.add(readDiseqilibriumElementsByRace(row, raceHeaders, locusPositions));
        }
    }

    workbook.close();

    return disequilibriumElements;
}

From source file:org.dash.valid.freq.HLAFrequenciesLoader.java

License:Open Source License

private void loadIndividualLocusFrequency(Frequencies freq, Locus locus)
        throws IOException, InvalidFormatException {
    List<String> singleLocusFrequencies = new ArrayList<String>();
    String extension = freq.equals(Frequencies.NMDP) ? ".xlsx" : ".xls";
    InputStream inputStream = HLAFrequenciesLoader.class.getClassLoader().getResourceAsStream(
            "frequencies/" + freq.getShortName() + "/" + locus.getFrequencyName() + extension);

    if (inputStream == null)
        return;/*w  w  w  .  ja va  2s. com*/

    Workbook workbook = WorkbookFactory.create(inputStream);

    // Return first sheet from the XLSX workbook
    Sheet mySheet = workbook.getSheetAt(0);

    // Get iterator to all the rows in current sheet
    Iterator<Row> rowIterator = mySheet.iterator();

    int firstRow = mySheet.getFirstRowNum();

    String cellValue = null;

    // Traversing over each row of XLSX file
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();

        if (row.getRowNum() == firstRow) {
            continue;
        } else {
            cellValue = row.getCell(0).getStringCellValue();
            if (!cellValue.contains(GLStringConstants.ASTERISK)) {
                cellValue = locus.getShortName() + GLStringConstants.ASTERISK + cellValue.substring(0, 2)
                        + GLStringUtilities.COLON + cellValue.substring(2);
            }
            singleLocusFrequencies.add(GLStringConstants.HLA_DASH + cellValue);
        }
    }

    individualLocusFrequencies.put(locus, singleLocusFrequencies);

    workbook.close();
}

From source file:org.datanucleus.store.excel.ExcelUtils.java

License:Open Source License

/**
 * Convenience method to find the row number of an object in the provided workbook.
 * For application-identity does a search for a row with the specified PK field values.
 * For datastore-identity does a search for the row with the datastore column having the specified value
 * @param op ObjectProvider for the object
 * @param wb Workbook//from   w  w w  .j av  a  2 s  .  c o  m
 * @param originalValue Use the original value of the identifiying fields if available (for when we are updating and using nondurable identity).
 * @param table The table representing this worksheet
 * @return The row number (or -1 if not found)
 */
public static int getRowNumberForObjectInWorkbook(ObjectProvider op, Workbook wb, boolean originalValue,
        Table table) {
    final AbstractClassMetaData cmd = op.getClassMetaData();
    if (cmd.getIdentityType() == IdentityType.APPLICATION) {
        ExecutionContext ec = op.getExecutionContext();
        ClassLoaderResolver clr = ec.getClassLoaderResolver();
        int[] pkFieldNumbers = cmd.getPKMemberPositions();

        List<Integer> pkFieldColList = new ArrayList(pkFieldNumbers.length);
        List pkFieldValList = new ArrayList(pkFieldNumbers.length);
        List<Class> pkFieldTypeList = new ArrayList(pkFieldNumbers.length);
        for (int i = 0; i < pkFieldNumbers.length; i++) {
            Object fieldValue = op.provideField(pkFieldNumbers[i]);
            AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNumbers[i]);
            RelationType relationType = mmd.getRelationType(clr);
            if (RelationType.isRelationSingleValued(relationType) && mmd.isEmbedded()) {
                // Embedded PC is part of PK (e.g JPA EmbeddedId)
                ObjectProvider embOP = ec.findObjectProvider(fieldValue);
                if (embOP == null) {
                    embOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, fieldValue,
                            false, op, pkFieldNumbers[i]);
                }
                AbstractClassMetaData embCmd = op.getExecutionContext().getMetaDataManager()
                        .getMetaDataForClass(mmd.getType(), clr);
                for (int j = 0; j < embCmd.getNoOfManagedMembers(); j++) {
                    // TODO Support nested embedded
                    AbstractMemberMetaData embMmd = embCmd.getMetaDataForManagedMemberAtAbsolutePosition(j);
                    List<AbstractMemberMetaData> embMmds = new ArrayList();
                    embMmds.add(mmd);
                    embMmds.add(embMmd);
                    pkFieldColList.add(
                            table.getMemberColumnMappingForEmbeddedMember(embMmds).getColumn(0).getPosition());
                    pkFieldValList.add(embOP.provideField(j));
                    pkFieldTypeList.add(embMmd.getType());
                }
            } else {
                pkFieldColList.add(table.getMemberColumnMappingForMember(mmd).getColumn(0).getPosition());
                pkFieldValList.add(fieldValue);
                pkFieldTypeList.add(mmd.getType());
            }
        }

        String sheetName = table.getName();
        final Sheet sheet = wb.getSheet(sheetName);
        if (sheet != null && sheet.getPhysicalNumberOfRows() > 0) {
            for (int i = sheet.getFirstRowNum(); i < sheet.getLastRowNum() + 1; i++) {
                Row row = sheet.getRow(i);
                if (row != null) {
                    boolean matches = true;

                    for (int j = 0; j < pkFieldColList.size(); j++) {
                        int colNumber = pkFieldColList.get(j);
                        Object fieldValue = pkFieldValList.get(j);
                        Class fieldType = pkFieldTypeList.get(j);
                        Cell cell = row.getCell(colNumber);
                        if (!cellMatches(cell, fieldType, fieldValue)) {
                            matches = false;
                            break;
                        }
                    }
                    if (matches) {
                        // Found the object with the correct PK values so return
                        return row.getRowNum();
                    }
                }
            }
        }
    } else if (cmd.getIdentityType() == IdentityType.DATASTORE) {
        String sheetName = table.getName();
        final Sheet sheet = wb.getSheet(sheetName);
        int datastoreIdColNo = table.getDatastoreIdColumn().getPosition();
        Object key = IdentityUtils.getTargetKeyForDatastoreIdentity(op.getInternalObjectId());
        if (sheet != null) {
            for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
                Row row = sheet.getRow(i);
                if (row != null) {
                    Cell cell = row.getCell(datastoreIdColNo);
                    if (cell != null && cellMatches(cell, key.getClass(), key)) {
                        return row.getRowNum();
                    }
                }
            }
        }
    } else {
        // Nondurable, so compare all applicable fields
        ExecutionContext ec = op.getExecutionContext();
        ClassLoaderResolver clr = ec.getClassLoaderResolver();
        int[] fieldNumbers = cmd.getAllMemberPositions();

        List<Integer> fieldColList = new ArrayList(fieldNumbers.length);
        List<Class> fieldTypeList = new ArrayList(fieldNumbers.length);
        List fieldValList = new ArrayList(fieldNumbers.length);
        for (int i = 0; i < fieldNumbers.length; i++) {
            AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumbers[i]);
            RelationType relationType = mmd.getRelationType(clr);
            Object fieldValue = null;
            if (originalValue) {
                Object oldValue = op
                        .getAssociatedValue(ObjectProvider.ORIGINAL_FIELD_VALUE_KEY_PREFIX + fieldNumbers[i]);
                if (oldValue != null) {
                    fieldValue = oldValue;
                } else {
                    fieldValue = op.provideField(fieldNumbers[i]);
                }
            } else {
                fieldValue = op.provideField(fieldNumbers[i]);
            }
            if (RelationType.isRelationSingleValued(relationType) && mmd.isEmbedded()) {
                // Embedded PC is part of PK (e.g JPA EmbeddedId)
                ObjectProvider embOP = ec.findObjectProvider(fieldValue);
                if (embOP == null) {
                    embOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, fieldValue,
                            false, op, fieldNumbers[i]);
                }
                AbstractClassMetaData embCmd = op.getExecutionContext().getMetaDataManager()
                        .getMetaDataForClass(mmd.getType(), clr);
                for (int j = 0; j < embCmd.getNoOfManagedMembers(); j++) {
                    // TODO Support nested embedded
                    AbstractMemberMetaData embMmd = embCmd.getMetaDataForManagedMemberAtAbsolutePosition(j);
                    List<AbstractMemberMetaData> embMmds = new ArrayList();
                    embMmds.add(mmd);
                    embMmds.add(embMmd);
                    fieldColList.add(
                            table.getMemberColumnMappingForEmbeddedMember(embMmds).getColumn(0).getPosition());
                    fieldTypeList.add(embMmd.getType());
                    fieldValList.add(embOP.provideField(j));
                }
            } else if (relationType == RelationType.NONE) {
                fieldColList.add(table.getMemberColumnMappingForMember(mmd).getColumn(0).getPosition());
                fieldTypeList.add(mmd.getType());
                fieldValList.add(fieldValue);
            }
        }

        String sheetName = table.getName();
        final Sheet sheet = wb.getSheet(sheetName);
        if (sheet != null && sheet.getPhysicalNumberOfRows() > 0) {
            for (int i = sheet.getFirstRowNum(); i < sheet.getLastRowNum() + 1; i++) {
                Row row = sheet.getRow(i);
                if (row != null) {
                    boolean matches = true;

                    for (int j = 0; j < fieldColList.size(); j++) {
                        int colNumber = fieldColList.get(j);
                        Class fieldType = fieldTypeList.get(j);
                        Object fieldValue = fieldValList.get(j);

                        Cell cell = row.getCell(colNumber);
                        if (!cellMatches(cell, fieldType, fieldValue)) {
                            matches = false;
                            break;
                        }
                    }
                    if (matches) {
                        // Found the object with the correct PK values so return
                        return row.getRowNum();
                    }
                }
            }
        }
    }
    return -1;
}