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

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

Introduction

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

Prototype

Cell getCell(int cellnum);

Source Link

Document

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

Usage

From source file:com.diversityarrays.kdxplore.importdata.bms.BmsExcelImportHelper.java

License:Open Source License

private List<ConsumerAndCellnum> buildConsumerByCellnum(BmsXlsTrialImportResult descriptionScanResult, Row row,
        int cellCount, Map<Integer, String> headingByCellNumber) {
    List<ConsumerAndCellnum> result = new ArrayList<>();

    Map<Integer, String> headingByCellnum = new HashMap<>();
    Map<String, Integer> cellnumByHeading = new HashMap<>();

    for (int cellnum = 0; cellnum < cellCount; ++cellnum) {
        Cell cell = row.getCell(cellnum);
        if (cell == null)
            continue;
        String heading = ExcelUtil.getCellStringValue(cell, ""); //$NON-NLS-1$
        headingByCellnum.put(cellnum, heading);
        cellnumByHeading.put(heading, cellnum);
    }//from www .j  a v  a2  s.c  om

    headingByCellNumber.putAll(headingByCellnum);

    for (Pair<String, Field> pair : descriptionScanResult.plotFactorFields) {
        Integer cellnum = cellnumByHeading.get(pair.first);
        if (cellnum != null) {
            result.add(new ConsumerAndCellnum(cellnum, new PlotFieldConsumer(pair.second)));
            cellnumByHeading.remove(pair.first);
            headingByCellnum.remove(cellnum);
        }
    }

    for (BmsExcelSection excelSection : BmsExcelSection.values()) {

        Map<String, SectionRowData> map = descriptionScanResult.attributesByDescriptionSection
                .get(excelSection);

        if (map != null) {
            for (String attributeName : map.keySet()) {
                Integer cellnum = cellnumByHeading.get(attributeName);
                if (cellnum != null) {
                    cellnumByHeading.remove(attributeName);
                    headingByCellnum.remove(cellnum);
                    if (!excelSection.isValueFromDescriptionWorksheet()) {
                        result.add(new ConsumerAndCellnum(cellnum,
                                excelSection.createCellValueConsumer(attributeName)));
                    }
                }
            }
        }
    }

    return result;
}

From source file:com.diversityarrays.kdxplore.importdata.bms.SectionRowData.java

License:Open Source License

private String getCellValue(Row row, int cellnum) {
    Cell cn = row.getCell(cellnum);
    String cn_value = cn == null ? "" : ExcelUtil.getCellStringValue(cn, "");
    return cn_value;
}

From source file:com.diversityarrays.kdxplore.importdata.excelio.KdxploreWorksheet.java

License:Open Source License

/**
 * Returns null if all the Cell values in the Row are blank.
 * @param row//from   w w  w  . ja va2s .  c  o m
 * @return List or null
 */
static public List<String> getCellValuesIfAnyNonBlank(Row row) {
    List<String> result = new ArrayList<>();

    boolean allBlank = true;
    int nCells = ExcelUtil.getCellCount(row);
    for (int cellIndex = 0; cellIndex < nCells; ++cellIndex) {
        Cell cell = row.getCell(cellIndex);
        String cellValue = "";
        if (cell != null) {
            cellValue = ExcelUtil.getCellStringValue(cell, "");
        }
        result.add(cellValue);
        if (!Check.isEmpty(cellValue)) {
            allBlank = false;
        }
    }

    return allBlank ? null : result;
}

From source file:com.diversityarrays.kdxplore.importdata.excelio.TrialWorksheet.java

License:Open Source License

@Override
public DataError processWorksheet(Sheet sheet, WorkbookReadResult wrr) {

    int nRows = ExcelUtil.getRowCount(sheet);
    for (int rowIndex = 0; rowIndex < nRows; ++rowIndex) {
        Row row = sheet.getRow(rowIndex);
        if (row == null) {
            continue;
        }//www .j ava 2 s.co  m

        int nCells = Math.min(2, ExcelUtil.getCellCount(row));
        String name = "";
        String value = "";
        for (int cellIndex = 0; cellIndex < nCells; ++cellIndex) {
            Cell cell = row.getCell(cellIndex);
            if (cell != null) {
                String s = ExcelUtil.getCellStringValue(cell, "");
                if (cellIndex == 0) {
                    name = s;
                } else if (cellIndex == 1) {
                    value = s;
                }
            }
        }

        ImportField importField = worksheetInfo.getFieldForHeading(name);
        if (importField == null) {
            TrialAttribute ta = new TrialAttribute();
            ta.setTrialAttributeName(name);
            ta.setTrialAttributeValue(value);
            wrr.trialAttributes.add(ta);
        } else {
            Either<String, Object> either = KDSmartDbUtil.convertValueOrError(Trial.class, importField.field,
                    value);
            if (either.isLeft()) {
                return new DataError(rowIndex, either.left());
            }

            try {
                importField.field.set(wrr.trial, either.right());
            } catch (IllegalArgumentException | IllegalAccessException e) {
                String msg = e.getClass().getSimpleName() + ": " + e.getMessage();
                return new DataError(rowIndex, msg);
            }
        }
    }
    return null;
}

From source file:com.dotosoft.dotoquiz.tools.OldApp.java

License:Apache License

private boolean showColumnHeader(Object data, String sheetName) {
    if (APPLICATION_TYPE.SHOW_COLUMN_HEADER.toString().equals(settings.getApplicationType())) {
        log.info("Show column header for \"" + sheetName + "\"");
        if (DATA_TYPE.EXCEL.toString().equals(settings.getDataType())) {
            Row rowData = (Row) data;
            Iterator<Cell> cellIterator = rowData.iterator();
            int columnCount = rowData.getRowNum();
            for (int i = 0; i < columnCount; i++) {
                Cell cell = rowData.getCell(i);
                log.info("\tColumn(" + i + "): " + cell.getStringCellValue());
            }//from w  ww . j av  a  2  s . c  o m
        } else if (DATA_TYPE.GOOGLESHEET.toString().equals(settings.getDataType())) {
            ListEntry listEntry = (ListEntry) data;
            int index = 0;
            for (String tag : listEntry.getCustomElements().getTags()) {
                log.info("\tColumn" + (index++) + ": " + tag);
            }
        }
        return true;
    }

    return false;
}

From source file:com.dotosoft.dotoquiz.tools.thirdparty.GooglesheetClient.java

License:Apache License

public static void updateSyncPicasa(Settings settings, String parseType, Object data, String picasaId,
        String imagePicasaURL, String isProcessed) throws IOException, ServiceException {
    String paramPIcasaId = DotoQuizStructure.getStructureKey(parseType, settings, "iAlbumIdPicasa");
    String paramImageURLPicasa = DotoQuizStructure.getStructureKey(parseType, settings, "iImageURLPicasa");
    String paramIsProcessed = DotoQuizStructure.getStructureKey(parseType, settings, "iIsProcessed");

    if (DATA_TYPE.EXCEL.toString().equals(settings.getDataType())) {
        Row rowData = (Row) data;

        if (StringUtils.hasValue(picasaId))
            rowData.getCell(Integer.parseInt(paramPIcasaId)).setCellValue(picasaId);
        if (StringUtils.hasValue(imagePicasaURL))
            rowData.getCell(Integer.parseInt(paramImageURLPicasa)).setCellValue(imagePicasaURL);
        rowData.getCell(Integer.parseInt(paramIsProcessed)).setCellValue(isProcessed);
    } else if (DATA_TYPE.GOOGLESHEET.toString().equals(settings.getDataType())) {
        ListEntry listEntry = (ListEntry) data;
        if (StringUtils.hasValue(picasaId))
            listEntry.getCustomElements().setValueLocal(paramPIcasaId, picasaId);
        if (StringUtils.hasValue(imagePicasaURL))
            listEntry.getCustomElements().setValueLocal(paramImageURLPicasa, imagePicasaURL);
        listEntry.getCustomElements().setValueLocal(paramIsProcessed, isProcessed);
        listEntry.update();/* w ww  .  j a v a  2  s .  com*/
    }
}

From source file:com.dotosoft.dotoquiz.tools.thirdparty.GooglesheetClient.java

License:Apache License

public static void updateClearPicasa(Settings settings, String parseType, Object data)
        throws IOException, ServiceException {
    String paramPIcasaId = DotoQuizStructure.getStructureKey(parseType, settings, "iAlbumIdPicasa");
    String paramImageURLPicasa = DotoQuizStructure.getStructureKey(parseType, settings, "iImageURLPicasa");
    String paramIsProcessed = DotoQuizStructure.getStructureKey(parseType, settings, "iIsProcessed");

    String picasaId = "";
    if (DATA_TYPE.EXCEL.toString().equals(settings.getDataType())) {
        Row rowData = (Row) data;
        picasaId = rowData.getCell(Integer.parseInt(paramPIcasaId)).getStringCellValue();
        rowData.getCell(Integer.parseInt(paramPIcasaId)).setCellValue(QuizConstant.EMPTY_STRING);
        rowData.getCell(Integer.parseInt(paramImageURLPicasa)).setCellValue(QuizConstant.EMPTY_STRING);
        rowData.getCell(Integer.parseInt(paramIsProcessed)).setCellValue(QuizConstant.EMPTY_STRING);
    } else if (DATA_TYPE.GOOGLESHEET.toString().equals(settings.getDataType())) {
        ListEntry listEntry = (ListEntry) data;
        picasaId = listEntry.getCustomElements().getValue(paramPIcasaId);
        listEntry.getCustomElements().setValueLocal(paramPIcasaId, QuizConstant.EMPTY_STRING);
        listEntry.getCustomElements().setValueLocal(paramImageURLPicasa, QuizConstant.EMPTY_STRING);
        listEntry.getCustomElements().setValueLocal(paramIsProcessed, QuizConstant.EMPTY_STRING);
        listEntry.update();//from w w  w  .j  a v  a  2s  . c  o m
    }

    log.info("Clear Data " + parseType + ": " + picasaId);
}

From source file:com.dotosoft.dotoquiz.tools.util.DotoQuizStructure.java

License:Apache License

private static String getValueFromRowData(String parseType, Settings setting, String key, Object data) {
    String paramKey = getStructureKey(parseType, setting, key);
    String result = "";
    if (DATA_TYPE.EXCEL.toString().equals(setting.getDataType())) {
        Row row = (Row) data;
        result = readCellAsString(row.getCell(Integer.parseInt(paramKey)), "");
    } else if (DATA_TYPE.GOOGLESHEET.toString().equals(setting.getDataType())) {
        ListEntry row = (ListEntry) data;
        result = row.getCustomElements().getValue(paramKey);
    }//from ww  w.  j a  va  2 s.  com

    return result;
}

From source file:com.dtec.validationgen.service.ValidationService.java

public String addContent() {
    try {//from  w  w  w .  j a va2  s  .  c  o  m
        XSSFWorkbook book = ioService.readExcel(templatePath);
        Map<String, String> mapFunction = new HashMap<String, String>();

        Sheet bookSheet = book.getSheetAt(0);
        mapFunction = ioService.readFunction("mapping.korn");
        Iterator<Row> rowIterator = bookSheet.rowIterator();
        String fieldName = "", validateString = "", resultCommand = "", comment = "", callfunction = "",
                keyFunction = "";
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            if (row.getCell(0).getStringCellValue().trim() == null
                    || row.getCell(0).getStringCellValue().trim() == "") {
                break;
            }
            callfunction = "PROCEDURE P_validate";
            fieldName = row.getCell(1).getStringCellValue().trim();
            validateString = row.getCell(10).getStringCellValue();
            String[] validateStrings = validateString.split("\\n");
            List<String> params = new ArrayList<>();
            for (String keyValidation : validateStrings) {
                keyFunction = getKeyMap(mapFunction, keyValidation);
                callfunction += "_" + keyFunction;
                comment += "--" + keyValidation + "\n";
                if (keyFunction.equals("expectvalue")) {
                    params.add(keyValidation.substring(keyValidation.indexOf("'") + 1,
                            keyValidation.lastIndexOf("'")));
                } else if (keyFunction.equals("expectvalues")) {
                    params.add(keyValidation.substring(keyValidation.indexOf("'") + 1,
                            keyValidation.indexOf("'", keyValidation.indexOf("'") + 1)));
                    params.add(
                            keyValidation
                                    .substring(
                                            keyValidation
                                                    .indexOf("'",
                                                            keyValidation.indexOf("'",
                                                                    keyValidation.indexOf("'") + 1) + 1)
                                                    + 1,
                                            keyValidation.lastIndexOf("'")));
                } else if (keyFunction.equals("intemplate")) {
                    params.add(keyValidation.substring(keyValidation.indexOf("'") + 1,
                            keyValidation.lastIndexOf("'")));
                } else if (keyFunction.equals("length")) {
                    params.add(keyValidation.substring(keyValidation.indexOf("'") + 1,
                            keyValidation.lastIndexOf("'")));
                }
            }
            callfunction += "(v_cs1_rec." + fieldName + ",'" + fieldName + "'";
            if (params.size() <= 0) {
                callfunction += ");";
            } else if (params.size() == 1) {
                callfunction += ",'" + params.get(0) + "');";
            } else if (params.size() == 2) {
                callfunction += ",'" + params.get(0) + "'" + ",'" + params.get(1) + "');";
            }

            resultCommand += "--" + fieldName + "\n" + comment + "BEGIN\n" + callfunction + "\nEND;\n\n";
            comment = "";
        }

        return resultCommand + "\n\n";
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(parent, "Error Gen Content", "Can't update Content",
                JOptionPane.ERROR_MESSAGE);
        Logger.getLogger(ValidationService.class.getName()).log(Level.SEVERE, null, ex);
        return "{content}";
    }

}

From source file:com.dtec.validationgen.test.TestService.java

public static void main(String... args) throws IOException {
    System.out.println("agbc number(5)".split(" ")[1].toUpperCase().contains("R("));
    System.out.println("number".toUpperCase().contains("NsUMBER") ? "NUMBER" : "VARCHAR2");
    TestService f = new TestService();
    f.changeString(f.abc);//from w ww. ja  v a2  s .com
    System.out.println(f.abc);

    XSSFWorkbook book = new IoService().readExcel("work around.xlsx");
    Map<String, String> mapFunction = new HashMap<String, String>();
    Sheet bookSheet = book.getSheetAt(0);
    Iterator<Row> rowIterator = bookSheet.rowIterator();
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();
        row.getCell(0).getStringCellValue();
        String fieldName = row.getCell(1).getStringCellValue().trim();
        String validateString = row.getCell(10).getStringCellValue();
        for (String keyValidation : validateString.split("\\n")) {
            System.out.println(keyValidation.trim());
        }
    }
    String keyValidation = "'abc' or 'ddd'";
    System.out.println(
            keyValidation.indexOf("'") + 1 + " " + keyValidation.indexOf("'", keyValidation.indexOf("'") + 1));
    String[] param = { "", "", "" };
    param[0] = keyValidation.substring(keyValidation.indexOf("'") + 1,
            keyValidation.indexOf("'", keyValidation.indexOf("'") + 1));
    param[1] = keyValidation.substring(
            keyValidation.indexOf("'", keyValidation.indexOf("'", keyValidation.indexOf("'") + 1) + 1) + 1,
            keyValidation.lastIndexOf("'"));

    System.out.println(Arrays.asList(param));
}