Example usage for org.apache.poi.ss.usermodel Sheet getRow

List of usage examples for org.apache.poi.ss.usermodel Sheet getRow

Introduction

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

Prototype

Row getRow(int rownum);

Source Link

Document

Returns the logical row (not physical) 0-based.

Usage

From source file:com.asakusafw.testdriver.excel.DefaultExcelRuleExtractorTest.java

License:Apache License

/**
 * nullity - empty string.//from  w  ww.  j a v  a2s .c  om
 * @throws Exception if occur
 */
@Test(expected = ExcelRuleExtractor.FormatException.class)
public void extractNullityCondition_empty() throws Exception {
    ExcelRuleExtractor extractor = new DefaultExcelRuleExtractor();
    Sheet sheet = sheet("nullity.xls");
    extractor.extractNullityCondition(sheet.getRow(9));
}

From source file:com.asakusafw.testdriver.excel.DefaultExcelRuleExtractorTest.java

License:Apache License

/**
 * nullity - blank cell./*ww w . j a  v  a  2s  .  co  m*/
 * @throws Exception if occur
 */
@Test(expected = ExcelRuleExtractor.FormatException.class)
public void extractNullityCondition_blank() throws Exception {
    ExcelRuleExtractor extractor = new DefaultExcelRuleExtractor();
    Sheet sheet = sheet("nullity.xls");
    extractor.extractNullityCondition(sheet.getRow(10));
}

From source file:com.asakusafw.testdriver.excel.DefaultExcelRuleExtractorTest.java

License:Apache License

/**
 * nullity - invalid cell./*from  ww  w.  jav a  2s . com*/
 * @throws Exception if occur
 */
@Test(expected = ExcelRuleExtractor.FormatException.class)
public void extractNullityCondition_invalid() throws Exception {
    ExcelRuleExtractor extractor = new DefaultExcelRuleExtractor();
    Sheet sheet = sheet("nullity.xls");
    extractor.extractNullityCondition(sheet.getRow(11));
}

From source file:com.asakusafw.testdriver.excel.ExcelSheetRuleProvider.java

License:Apache License

private <T> VerifyRule resolve(DataModelDefinition<T> definition, VerifyContext context, Sheet sheet,
        ExcelRuleExtractor extractor) throws ExcelRuleExtractor.FormatException {
    assert definition != null;
    assert context != null;
    assert sheet != null;
    assert extractor != null;

    VerifyRuleBuilder builder = new VerifyRuleBuilder(definition);
    Set<DataModelCondition> modelPredicates = extractor.extractDataModelCondition(sheet);
    if (modelPredicates.contains(DataModelCondition.IGNORE_ABSENT)) {
        builder.acceptIfAbsent();/*from  w  ww .  ja v  a  2  s.  co m*/
    }
    if (modelPredicates.contains(DataModelCondition.IGNORE_UNEXPECTED)) {
        builder.acceptIfUnexpected();
    }
    if (modelPredicates.contains(DataModelCondition.IGNORE_MATCHED) == false) {
        int start = extractor.extractPropertyRowStartIndex(sheet);
        int end = sheet.getLastRowNum() + 1;
        for (int i = start; i < end; i++) {
            Row row = sheet.getRow(i);
            if (row == null) {
                continue;
            }
            resolveRow(builder, definition, context, row, extractor);
        }
    }
    return builder.toVerifyRule();
}

From source file:com.asakusafw.testdriver.excel.ExcelSheetSinkTest.java

License:Apache License

/**
 * many columns.//from   w w w . jav  a  2  s .  c om
 * @throws Exception if occur
 */
@Test
public void many_columns() throws Exception {
    Object[] value = new Object[256];
    Map<PropertyName, PropertyType> map = new TreeMap<>();
    for (int i = 0; i < value.length; i++) {
        map.put(PropertyName.newInstance(String.format("p%04x", i)), PropertyType.INT);
        value[i] = i;
    }
    ArrayModelDefinition def = new ArrayModelDefinition(map);

    File file = folder.newFile("temp.xls");
    ExcelSheetSinkFactory factory = new ExcelSheetSinkFactory(file);
    try (DataModelSink sink = factory.createSink(def, new TestContext.Empty())) {
        sink.put(def.toReflection(value));
    }

    try (InputStream in = new FileInputStream(file)) {
        Workbook workbook = Util.openWorkbookFor(file.getPath(), in);
        Sheet sheet = workbook.getSheetAt(0);
        Row title = sheet.getRow(0);
        assertThat(title.getLastCellNum(), is((short) 256));

        Row content = sheet.getRow(1);
        for (int i = 0; i < title.getLastCellNum(); i++) {
            assertThat(content.getCell(i).getNumericCellValue(), is((double) (Integer) value[i]));
        }
    }
}

From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractor.java

License:Apache License

private String getStringCell(Sheet sheet, int rowIndex, int colIndex) {
    assert sheet != null;
    Row row = sheet.getRow(rowIndex);
    if (row == null) {
        return null;
    }//from  ww  w  .  j  a v a 2s . c om
    Cell cell = row.getCell(colIndex);
    if (cell == null || cell.getCellType() != Cell.CELL_TYPE_STRING) {
        return null;
    }
    return cell.getStringCellValue();
}

From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractorTest.java

License:Apache License

/**
 * names.//from  ww  w .  j  a  v  a 2  s .c o  m
 * @throws Exception if failed
 */
@Test
public void extractName() throws Exception {
    ExcelRuleExtractor extractor = new LegacyExcelRuleExtractor();
    Sheet sheet = sheet("legacy-rule.xls");
    assertThat(extractor.extractName(sheet.getRow(3)), is("sid"));
    assertThat(extractor.extractName(sheet.getRow(4)), is("version_no"));
    assertThat(extractor.extractName(sheet.getRow(5)), is("rgst_datetime"));
    assertThat(extractor.extractName(sheet.getRow(6)), is("updt_datetime"));
    assertThat(extractor.extractName(sheet.getRow(7)), is("code"));
}

From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractorTest.java

License:Apache License

/**
 * empty names./*from  w w  w  .ja v a  2  s .  c o m*/
 * @throws Exception if failed
 */
@Test
public void extractName_empty() throws Exception {
    ExcelRuleExtractor extractor = new LegacyExcelRuleExtractor();
    Sheet sheet = sheet("invalid.xls");
    assertThat(extractor.extractName(sheet.getRow(3)), is(nullValue()));
    assertThat(extractor.extractName(sheet.getRow(4)), is(nullValue()));
}

From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractorTest.java

License:Apache License

/**
 * invalid names./*from   w ww  . j a v  a  2s . c o m*/
 * @throws Exception if failed
 */
@Test(expected = ExcelRuleExtractor.FormatException.class)
public void extractName_invalid() throws Exception {
    ExcelRuleExtractor extractor = new LegacyExcelRuleExtractor();
    Sheet sheet = sheet("invalid.xls");
    extractor.extractName(sheet.getRow(5));
}

From source file:com.asakusafw.testdriver.excel.legacy.LegacyExcelRuleExtractorTest.java

License:Apache License

/**
 * value conditions./*from  w  w w . ja v a 2s  .c  o m*/
 * @throws Exception if failed
 */
@Test
public void extractValueCondition() throws Exception {
    ExcelRuleExtractor extractor = new LegacyExcelRuleExtractor();
    Sheet sheet = sheet("legacy-rule.xls");
    assertThat(extractor.extractValueCondition(sheet.getRow(3)), is(ValueConditionKind.ANY));
    assertThat(extractor.extractValueCondition(sheet.getRow(4)), is(ValueConditionKind.EQUAL));
    assertThat(extractor.extractValueCondition(sheet.getRow(5)), is(ValueConditionKind.CONTAIN));
    assertThat(extractor.extractValueCondition(sheet.getRow(6)), is(ValueConditionKind.NOW));
    assertThat(extractor.extractValueCondition(sheet.getRow(7)), is(ValueConditionKind.TODAY));
}