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.sakaiproject.gradebook.gwt.server.ImportExportUtilityImpl.java

License:Educational Community License

private ImportExportDataFile processScantronXls(org.apache.poi.ss.usermodel.Sheet cur, String fileName,
        ImportSettings settings) {//from  w w w  . ja va  2s.  co  m
    ImportExportDataFile data = new ImportExportDataFile();
    Iterator<Row> rowIter = cur.rowIterator();
    StringBuilder err = new StringBuilder("Scantron File with errors");
    boolean stop = false;

    org.apache.poi.ss.usermodel.Cell studentIdHeader = findCellWithTextonSheetForPoi(cur,
            scantronStudentIdHeader);
    org.apache.poi.ss.usermodel.Cell scoreHeader = findCellWithTextonSheetForPoi(cur, scantronScoreHeader);
    if (studentIdHeader == null) {
        err.append("There is no column with the header student_id");
        stop = true;
    }

    if (scoreHeader == null) {
        // check for a rescore header - GRBK-407
        scoreHeader = findCellWithTextonSheetForPoi(cur, scantronRescoreHeader);
        if (scoreHeader == null) {
            err.append("There is no column with the header score");
            stop = true;
        }
    }

    if (!stop) {
        data.addRow(createScantronHeaderRow(fileName));

        // GRBK-514
        if (settings.isJustStructure()) {
            return data;
        }

        while (rowIter.hasNext()) {
            Row curRow = rowIter.next();
            org.apache.poi.ss.usermodel.Cell score = null;
            org.apache.poi.ss.usermodel.Cell id = null;

            id = curRow.getCell(studentIdHeader.getColumnIndex());
            score = curRow.getCell(scoreHeader.getColumnIndex());
            if (id == null) {
                err.append("Skipped Row ");
                err.append(curRow.getRowNum());
                err.append(" does not have a student id column<br>");
                continue;
            }
            String idStr, scoreStr;

            // IF the row contains the header, meaning it is the header row, we want to skip it. 
            if (!id.equals(studentIdHeader)) {
                // FIXME - need to decide if this is OK for everyone, not everyone will have an ID as a 
                idStr = getDataFromCellAsStringRegardlessOfCellType(id, false);
                scoreStr = getDataFromCellAsStringRegardlessOfCellType(score, true);
                String[] ent = new String[2];
                ent[0] = idStr;
                ent[1] = scoreStr;

                data.addRow(ent);
            }
        }
    }
    return data;

}

From source file:org.simplesite.commons.utils.excel.ExportExcel.java

License:Open Source License

/**
 * ?annotation.ExportField?//w ww  . j a v a2s .  c  o  m
 * @return list ?
 */
public <E> ExportExcel setDataList(List<E> list) {
    for (E e : list) {
        int colunm = 0;
        Row row = this.addRow();
        StringBuilder sb = new StringBuilder();
        for (Object[] os : annotationList) {
            ExcelField ef = (ExcelField) os[0];
            Object val = null;
            // Get entity value
            try {
                if (StringUtils.isNotBlank(ef.value())) {
                    val = Reflections.invokeGetter(e, ef.value());
                } else {
                    if (os[1] instanceof Field) {
                        val = Reflections.invokeGetter(e, ((Field) os[1]).getName());
                    } else if (os[1] instanceof Method) {
                        val = Reflections.invokeMethod(e, ((Method) os[1]).getName(), new Class[] {},
                                new Object[] {});
                    }
                }
                // If is dict, get dict label
                if (StringUtils.isNotBlank(ef.dictType())) {
                    //val = DictUtils.getDictLabel(val==null?"":val.toString(), ef.dictType(), "");
                    val = val == null ? "" : val.toString();
                }
            } catch (Exception ex) {
                // Failure to ignore
                log.info(ex.toString());
                val = "";
            }
            this.addCell(row, colunm++, val, ef.align(), ef.fieldType());
            sb.append(val + ", ");
        }
        log.debug("Write success: [" + row.getRowNum() + "] " + sb.toString());
    }
    return this;
}

From source file:org.spdx.rdfparser.LicenseSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);//from www .  j a  v a  2  s. c o m
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.AnnotationsSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);// w  ww .  j a  va 2s  .  c o m
        if (REQUIRED[i] && cell == null) {
            return "Required cell " + HEADER_TITLES[i] + " missing for row " + String.valueOf(row.getRowNum())
                    + " in annotation sheet";
        }
        if (i == TYPE_COL && cell.getStringCellValue() != null) {
            AnnotationType type = Annotation.TAG_TO_ANNOTATION_TYPE.get(cell.getStringCellValue());
            if (type == null) {
                return "Invalid annotation type in row " + String.valueOf(row) + ": "
                        + cell.getStringCellValue();
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.DeprecatedLicenseSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*from www. ja va 2s.  c o m*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.ExternalRefsSheet.java

License:Apache License

/**
 * @param row/*from  w ww .j  av  a2  s  .com*/
 * @return
 */
private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.LicenseSheet.java

License:Apache License

public void add(SpdxListedLicense license) {
    Row row = addRow();
    Cell nameCell = row.createCell(COL_NAME);
    nameCell.setCellValue(license.getName());
    Cell idCell = row.createCell(COL_ID);
    idCell.setCellValue(license.getLicenseId());
    if (license.getSeeAlso() != null && license.getSeeAlso().length > 0) {
        Cell sourceUrlCell = row.createCell(COL_SOURCE_URL);
        StringBuilder sb = new StringBuilder();
        sb.append(license.getSeeAlso()[0]);
        for (int i = 1; i < license.getSeeAlso().length; i++) {
            sb.append(' ');
            sb.append(license.getSeeAlso()[i]);
        }/*from   www . j a  v  a  2 s .  co  m*/
        sourceUrlCell.setCellValue(sb.toString());
    }
    if (license.getComment() != null) {
        Cell notesCell = row.createCell(COL_NOTES);
        notesCell.setCellValue(license.getComment());
    }
    if (license.getStandardLicenseHeader() != null) {
        Cell standardLicenseHeaderCell = row.createCell(COL_STANDARD_LICENSE_HEADER);
        standardLicenseHeaderCell.setCellValue(license.getStandardLicenseHeader());
    }
    Cell templateCell = row.createCell(COL_TEMPLATE);
    String templateText = license.getStandardLicenseTemplate();
    if (templateText == null || templateText.trim().isEmpty()) {
        templateText = license.getLicenseText();
    }
    setTemplateText(templateCell, license.getStandardLicenseTemplate(), license.getLicenseId(), workbookPath);
    if (license.isOsiApproved()) {
        Cell osiApprovedCell = row.createCell(COL_OSI_APPROVED);
        osiApprovedCell.setCellValue("YES");
    }
    if (row.getRowNum() == firstRowNum + 1) {
        // need to add version release date
        Cell versionCell = row.createCell(COL_VERSION);
        versionCell.setCellValue(this.version);
        Cell releaseDateCell = row.createCell(COL_RELEASE_DATE);
        releaseDateCell.setCellValue(this.releaseDate);
    }
}

From source file:org.spdx.spdxspreadsheet.OriginsSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/* ww w. j a v  a2s.c o  m*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum() + " in Origins Spreadsheet");
            }
        } else {
            if (i == CREATED_COL) {
                if (!(cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) {
                    return "Created column in origin spreadsheet is not of type Date";
                }
            }
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.OriginsSheetV2d0.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/* w  ww .  ja va  2 s  .co  m*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum() + " in Origins Spreadsheet");
            }
        } else {
            if (i == CREATED_COL) {
                if (!(cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) {
                    return "Created column in origin spreadsheet is not of type Date";
                }
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.PackageInfoSheetV09d2.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*from   w w  w .ja  v  a  2s  . c  om*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            if (i == DECLARED_LICENSE_COL || i == CONCLUDED_LICENSE_COL) {
                try {
                    SPDXLicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue());
                } catch (SpreadsheetException ex) {
                    if (i == DECLARED_LICENSE_COL) {
                        return "Invalid declared license in row " + String.valueOf(row.getRowNum())
                                + " detail: " + ex.getMessage();
                    } else {
                        return "Invalid seen license in row " + String.valueOf(row.getRowNum()) + " detail: "
                                + ex.getMessage();
                    }
                }
            } else if (i == LICENSE_INFO_IN_FILES_COL) {
                String[] licenses = row.getCell(LICENSE_INFO_IN_FILES_COL).getStringCellValue().split(",");
                if (licenses.length < 1) {
                    return "Missing licenss infos in files";
                }
                for (int j = 0; j < licenses.length; j++) {
                    try {
                        SPDXLicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue().trim());
                    } catch (SpreadsheetException ex) {
                        return "Invalid license infos in row " + String.valueOf(row.getRowNum()) + " detail: "
                                + ex.getMessage();
                    }
                }
            }
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}