Example usage for org.apache.poi.ss.usermodel Cell getColumnIndex

List of usage examples for org.apache.poi.ss.usermodel Cell getColumnIndex

Introduction

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

Prototype

int getColumnIndex();

Source Link

Document

Returns column index of this cell

Usage

From source file:org.bbreak.excella.reports.tag.ImageParamParser.java

License:Open Source License

/**
 * ??//from ww  w. ja va 2  s .co m
 * 
 * @param sheet ?
 * @param cell 
 * @param filePath ?
 * @param dx1 ??
 * @param dy1 ???
 * @param scale ???
 * @throws ParseException
 */
public void replaceImageValue(Sheet sheet, Cell cell, String filePath, Integer dx1, Integer dy1, Double scale)
        throws ParseException {

    Workbook workbook = sheet.getWorkbook();

    int format = -1;
    if (filePath.toLowerCase().endsWith(JPEG_SUFFIX) || filePath.toLowerCase().endsWith(JPG_SUFFIX)) {
        format = Workbook.PICTURE_TYPE_JPEG;
    } else if (filePath.toLowerCase().endsWith(PNG_SUFFIX)) {
        format = Workbook.PICTURE_TYPE_PNG;
    }
    if (format == -1) {
        throw new ParseException(cell,
                "????????" + filePath);
    }

    byte[] bytes = null;
    InputStream is = null;
    try {
        is = new FileInputStream(filePath);
        bytes = IOUtils.toByteArray(is);
    } catch (Exception e) {
        throw new ParseException(cell, e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            throw new ParseException(cell, e);
        }
    }

    int pictureIdx = workbook.addPicture(bytes, format);

    CreationHelper helper = workbook.getCreationHelper();

    @SuppressWarnings("rawtypes")
    Drawing drawing = drawingCash.get(sheet);
    if (drawing == null) {
        drawing = sheet.createDrawingPatriarch();
        drawingCash.put(sheet, drawing);
    }

    ClientAnchor anchor = helper.createClientAnchor();

    anchor.setRow1(cell.getRowIndex());
    anchor.setCol1(cell.getColumnIndex());
    anchor.setRow2(cell.getRowIndex() + 1);
    anchor.setCol2(cell.getColumnIndex() + 1);
    if (dx1 != null) {
        anchor.setDx1(dx1);
    }
    if (dy1 != null) {
        anchor.setDy1(dy1);
    }

    Picture picture = drawing.createPicture(anchor, pictureIdx);
    picture.resize(scale);

}

From source file:org.bbreak.excella.reports.tag.RemoveParamParser.java

License:Open Source License

@Override
public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException {
    // ????/*  w w w  . j  a v  a2  s .com*/
    ParsedReportInfo parsedReportInfo = new ParsedReportInfo();
    parsedReportInfo.setRowIndex(tagCell.getRowIndex());
    parsedReportInfo.setColumnIndex(tagCell.getColumnIndex());
    parsedReportInfo.setDefaultRowIndex(tagCell.getRowIndex());
    parsedReportInfo.setDefaultColumnIndex(tagCell.getColumnIndex());
    return parsedReportInfo;
}

From source file:org.bbreak.excella.reports.tag.RowRepeatParamParser.java

License:Open Source License

@Override
public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException {

    Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue());

    // ?//from w w w  .  j  av  a2  s  .  co  m
    checkParam(paramDef, tagCell);

    String tag = tagCell.getStringCellValue();
    ReportsParserInfo reportsParserInfo = (ReportsParserInfo) data;
    // ?
    Object[] paramValues = null;
    try {
        // ?
        boolean rowShift = false;
        if (paramDef.containsKey(PARAM_ROW_SHIFT)) {
            rowShift = Boolean.valueOf(paramDef.get(PARAM_ROW_SHIFT));
        }
        // ??
        boolean hideDuplicate = false;
        if (paramDef.containsKey(PARAM_DUPLICATE)) {
            hideDuplicate = Boolean.valueOf(paramDef.get(PARAM_DUPLICATE));
        }
        // ?
        Integer breakNum = null;
        if (paramDef.containsKey(PARAM_BREAK_NUM)) {
            breakNum = Integer.valueOf(paramDef.get(PARAM_BREAK_NUM));
        }
        // 
        boolean changeBreak = false;
        if (paramDef.containsKey(PARAM_CHANGE_BREAK)) {
            changeBreak = Boolean.valueOf(paramDef.get(PARAM_CHANGE_BREAK));
        }
        // ?
        Integer repeatNum = null;
        if (paramDef.containsKey(PARAM_REPEAT_NUM)) {
            repeatNum = Integer.valueOf(paramDef.get(PARAM_REPEAT_NUM));
        }
        // ??
        Integer minRepeatNum = null;
        if (paramDef.containsKey(PARAM_MIN_REPEAT_NUM)) {
            minRepeatNum = Integer.valueOf(paramDef.get(PARAM_MIN_REPEAT_NUM));
        }
        // ?
        boolean sheetLink = false;
        if (paramDef.containsKey(PARAM_SHEET_LINK)) {
            sheetLink = Boolean.valueOf(paramDef.get(PARAM_SHEET_LINK));
        }
        // 
        String propertyName = null;
        if (paramDef.containsKey(PARAM_PROPERTY)) {
            propertyName = paramDef.get(PARAM_PROPERTY);
        }
        // ???
        String replaceParam = paramDef.get(PARAM_VALUE);
        // 
        if (ReportsUtil.VALUE_SHEET_NAMES.equals(replaceParam)) {
            // ??
            paramValues = ReportsUtil.getSheetNames(reportsParserInfo.getReportBook()).toArray();
        } else if (ReportsUtil.VALUE_SHEET_VALUES.equals(replaceParam)) {
            // 
            paramValues = ReportsUtil.getSheetValues(reportsParserInfo.getReportBook(), propertyName,
                    reportsParserInfo.getReportParsers()).toArray();
        } else {
            // ???
            ParamInfo paramInfo = reportsParserInfo.getParamInfo();
            if (paramInfo != null) {
                paramValues = getParamData(paramInfo, replaceParam);
            }
        }

        if (paramValues == null || paramValues.length == 0) {
            // ?
            paramValues = new Object[] { null };
        }

        // ?
        int shiftNum = paramValues.length;
        // ?
        int paramLength = paramValues.length;

        // ???????
        if (minRepeatNum != null && shiftNum < minRepeatNum) {
            Object[] tmpValues = new Object[minRepeatNum];
            System.arraycopy(paramValues, 0, tmpValues, 0, paramValues.length);
            paramValues = tmpValues;
            shiftNum = paramValues.length;
            paramLength = paramValues.length;
        }

        // ???
        int defaultFromCellRowIndex = tagCell.getRowIndex();
        // ???
        int defaultFromCellColIndex = tagCell.getColumnIndex();

        // ???
        int unitRowSize = 1;

        // ???
        List<CellRangeAddress> maegedAddresses = new ArrayList<CellRangeAddress>();
        for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
            CellRangeAddress targetAddress = sheet.getMergedRegion(i);
            maegedAddresses.add(targetAddress);
        }

        // ???
        if (maegedAddresses.size() > 0) {
            // ?????????????
            for (CellRangeAddress curMergedAdress : maegedAddresses) {
                if (defaultFromCellColIndex == curMergedAdress.getFirstColumn()
                        && defaultFromCellRowIndex == curMergedAdress.getFirstRow()) {
                    // ????????????
                    // ??????
                    unitRowSize = curMergedAdress.getLastRow() - curMergedAdress.getFirstRow() + 1;

                    // ??????
                    shiftNum = shiftNum * unitRowSize;
                }
            }
        }

        // ???
        // ?????
        tagCell = new CellClone(tagCell);
        List<Cell> cellList = new ArrayList<Cell>();
        int defaultToOverCellRowIndex = tagCell.getRowIndex() + unitRowSize;
        for (int i = defaultFromCellRowIndex; i < defaultToOverCellRowIndex; i++) {
            Row targetCellRow = sheet.getRow(i);
            cellList.add(new CellClone(targetCellRow.getCell(tagCell.getColumnIndex())));
        }

        // ?
        if (repeatNum != null && repeatNum < shiftNum) {
            // ??????
            // ????????????????
            // ?????
            shiftNum = repeatNum * unitRowSize;

            // ??????
            paramLength = repeatNum;
        }

        // ?
        if (shiftNum > 1) {
            // ?(????????)
            int shiftRowSize = tagCell.getRowIndex() + shiftNum - unitRowSize - 1;
            if (!rowShift) {
                // ?????
                CellRangeAddress rangeAddress = new CellRangeAddress(tagCell.getRowIndex(), shiftRowSize,
                        tagCell.getColumnIndex(), tagCell.getColumnIndex());
                PoiUtil.insertRangeDown(sheet, rangeAddress);
            } else {
                // ?????
                // #35 POI???????????????????
                // ??????0????????
                CellRangeAddress rangeAddress = new CellRangeAddress(tagCell.getRowIndex() + unitRowSize,
                        tagCell.getRowIndex() + shiftNum - 1, 0, PoiUtil.getLastColNum(sheet));
                PoiUtil.insertRangeDown(sheet, rangeAddress);
                // int shiftStartRow = tagCell.getRowIndex() + 1;
                // int shiftEndRow = sheet.getLastRowNum();
                // if ( shiftEndRow < shiftStartRow) {
                // // ????????????????
                // // ????????????
                // shiftEndRow = shiftStartRow + 1;
                // }
                // sheet.shiftRows( shiftStartRow, shiftEndRow, shiftNum - unitRowSize);
            }
        }

        // ???
        Workbook workbook = sheet.getWorkbook();
        String sheetName = workbook.getSheetName(workbook.getSheetIndex(sheet));
        // ??
        List<String> sheetNames = ReportsUtil.getSheetNames(reportsParserInfo.getReportBook());
        // ?
        List<Object> resultValues = new ArrayList<Object>();
        // ??(beforeValue)
        Object beforeValue = null;

        // ?
        int valueIndex = -1;
        // ?????
        for (int rowIndex = 0; rowIndex < shiftNum; rowIndex++) {
            // ??
            Row row = sheet.getRow(tagCell.getRowIndex() + rowIndex);
            if (row == null) {
                row = sheet.createRow(tagCell.getRowIndex() + rowIndex);
            }
            // ??
            Cell cell = row.getCell(tagCell.getColumnIndex());
            if (cell == null) {
                cell = row.createCell(tagCell.getColumnIndex());
            }
            // ????(null)
            Object value = null;

            // ??????
            // ??0???(?????????)???????
            int cellIndex = rowIndex % unitRowSize;

            // ?????????
            boolean skipRow = false;
            if (cellIndex != 0) {
                skipRow = true;
            } else {
                valueIndex++;
            }

            // (?)
            PoiUtil.copyCell(cellList.get(cellIndex), cell);

            // ?
            Object currentValue = paramValues[valueIndex];
            // ??=true???????????
            boolean duplicateValue = false;
            if (beforeValue != null && currentValue != null && beforeValue.equals(currentValue)) {
                // ???
                duplicateValue = true;
            }
            if (!skipRow && !(hideDuplicate && duplicateValue)) {
                // ??=true
                // ??????????????
                value = currentValue;
            }
            if (log.isDebugEnabled()) {
                log.debug("[??=" + sheetName + ",=(" + cell.getRowIndex() + ","
                        + cell.getColumnIndex() + ")]  " + tag + "  " + value);
            }
            PoiUtil.setCellValue(cell, value);
            resultValues.add(value);

            // ?
            if (sheetLink) {
                if (!skipRow && valueIndex < sheetNames.size()) {
                    PoiUtil.setHyperlink(cell, HyperlinkType.DOCUMENT,
                            "'" + sheetNames.get(valueIndex) + "'!A1");
                    if (log.isDebugEnabled()) {
                        log.debug("[??=" + sheetName + ",=(" + cell.getRowIndex() + ","
                                + cell.getColumnIndex() + ")]  Hyperlink  " + "'"
                                + sheetNames.get(valueIndex) + "'!A1");
                    }
                }
            }

            // 
            if (!skipRow) {
                if (breakNum != null && valueIndex != 0 && valueIndex % breakNum == 0) {
                    // ???
                    sheet.setRowBreak(row.getRowNum() - 1);
                }
                if (changeBreak && valueIndex != 0 && !duplicateValue) {
                    // ???
                    sheet.setRowBreak(row.getRowNum() - 1);
                }
            }

            // ??
            // ??????????
            // ????????????
            if (!skipRow && unitRowSize > 1) {
                // ???
                boolean mergedRegionFlag = false;
                if (rowShift && valueIndex != 0) {
                    // ?????????????
                    mergedRegionFlag = true;
                } else if (!rowShift && paramLength > valueIndex + 1) {
                    // ????????????
                    mergedRegionFlag = true;
                }

                // ??
                if (mergedRegionFlag) {
                    CellRangeAddress rangeAddress = new CellRangeAddress(cell.getRowIndex(),
                            cell.getRowIndex() + unitRowSize - 1, cell.getColumnIndex(), cell.getColumnIndex());
                    sheet.addMergedRegion(rangeAddress);

                    // ????????????
                    beforeValue = currentValue;
                }
            }

            // ???????
            if (unitRowSize == 1) {
                beforeValue = currentValue;
            }

        }

        // ????
        ParsedReportInfo parsedReportInfo = new ParsedReportInfo();
        parsedReportInfo.setParsedObject(resultValues);
        // ??
        parsedReportInfo.setDefaultRowIndex(tagCell.getRowIndex() + unitRowSize - 1);
        parsedReportInfo.setDefaultColumnIndex(tagCell.getColumnIndex());
        parsedReportInfo.setRowIndex(tagCell.getRowIndex() + shiftNum - 1);
        parsedReportInfo.setColumnIndex(tagCell.getColumnIndex());
        if (log.isDebugEnabled()) {
            log.debug(parsedReportInfo);
        }

        return parsedReportInfo;

    } catch (Exception e) {
        throw new ParseException(tagCell, e);
    }
}

From source file:org.bbreak.excella.reports.tag.SingleParamParser.java

License:Open Source License

@Override
public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException {
    List<String> tmpTargets = new ArrayList<String>();
    StringTokenizer tagTokenizer = new StringTokenizer(tagCell.getStringCellValue(), getTag());
    while (tagTokenizer.hasMoreTokens()) {
        tmpTargets.add(tagTokenizer.nextToken());
    }//from   w w w. j ava2s  .  c o  m

    List<String> finalTargets = new ArrayList<String>();
    for (String tempTarget : tmpTargets) {
        if (tempTarget.startsWith(TagParser.TAG_PARAM_PREFIX)
                && !tempTarget.endsWith(TagParser.TAG_PARAM_SUFFIX)) {
            finalTargets.add(tempTarget.substring(0, tempTarget.indexOf(TagParser.TAG_PARAM_SUFFIX) + 1));
            finalTargets.add(tempTarget.substring(tempTarget.indexOf(TagParser.TAG_PARAM_SUFFIX) + 1));
            continue;
        }
        finalTargets.add(tempTarget);
    }

    ParsedReportInfo parsedReportInfo = new ParsedReportInfo();
    List<Object> paramValues = new ArrayList<Object>();

    for (int i = 0; i < finalTargets.size(); i++) {
        String target = finalTargets.get(i);
        if (!target.startsWith(TagParser.TAG_PARAM_PREFIX)) {
            // ???
            paramValues.add(target);
            continue;
        } else {
            // ?????
            target = getTag() + target;
        }

        Map<String, String> paramDef = TagUtil.getParams(target);

        // ?
        checkParam(paramDef, tagCell);

        ReportsParserInfo reportsParserInfo = (ReportsParserInfo) data;

        ParamInfo paramInfo = reportsParserInfo.getParamInfo();

        if (paramInfo != null) {
            // ???
            String replaceParam = paramDef.get(PARAM_VALUE);

            // ???
            paramValues.add(getParamData(paramInfo, replaceParam));

            if (log.isDebugEnabled()) {
                Workbook workbook = sheet.getWorkbook();
                String sheetName = workbook.getSheetName(workbook.getSheetIndex(sheet));
                log.debug("[??=" + sheetName + ",=(" + tagCell.getRowIndex() + ","
                        + tagCell.getColumnIndex() + ")] " + tagCell.getStringCellValue() + "  "
                        + paramValues.get(i));
            }
        }
    }

    // ?
    if (paramValues.size() > 1) {
        StringBuilder builder = new StringBuilder();
        for (Object object : paramValues) {
            if (object == null) {
                continue;
            }
            if (object instanceof Date) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
                builder.append(sdf.format(object));
                continue;
            }
            builder.append(object);
        }
        PoiUtil.setCellValue(tagCell, builder.toString());
        parsedReportInfo.setParsedObject(builder.toString());
    } else if (paramValues.size() == 1) {
        PoiUtil.setCellValue(tagCell, paramValues.get(0));
        parsedReportInfo.setParsedObject(paramValues.get(0));
    }
    parsedReportInfo.setDefaultRowIndex(tagCell.getRowIndex());
    parsedReportInfo.setDefaultColumnIndex(tagCell.getColumnIndex());
    parsedReportInfo.setRowIndex(tagCell.getRowIndex());
    parsedReportInfo.setColumnIndex(tagCell.getColumnIndex());

    return parsedReportInfo;
}

From source file:org.bbreak.excella.reports.tag.SumParamParser.java

License:Open Source License

@Override
public ParsedReportInfo parse(Sheet sheet, Cell tagCell, Object data) throws ParseException {

    Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue());

    ReportsParserInfo reportsParserInfo = (ReportsParserInfo) data;

    ParamInfo paramInfo = reportsParserInfo.getParamInfo();

    Object paramValue = null;// w w w.  j  a v  a  2s. c  om

    if (paramInfo != null) {
        // ?
        // ???
        String replaceParam = paramDef.get(PARAM_VALUE);

        paramValue = ReportsUtil.getSumValue(paramInfo, replaceParam, reportsParserInfo.getReportParsers());

        // ?
        PoiUtil.setCellValue(tagCell, paramValue);

    }

    // ????
    ParsedReportInfo parsedReportInfo = new ParsedReportInfo();
    parsedReportInfo.setParsedObject(paramValue);
    parsedReportInfo.setRowIndex(tagCell.getRowIndex());
    parsedReportInfo.setColumnIndex(tagCell.getColumnIndex());
    parsedReportInfo.setDefaultRowIndex(tagCell.getRowIndex());
    parsedReportInfo.setDefaultColumnIndex(tagCell.getColumnIndex());

    return parsedReportInfo;
}

From source file:org.bbreak.excella.trans.tag.sheet2java.SheetToJavaExecuterTest.java

License:Open Source License

@Test
@SuppressWarnings("unchecked")
public final void testSheetToJavaExecuter() throws ParseException, java.text.ParseException {

    Workbook workbook = getWorkbook();/*from  w w w  .j a  v  a  2 s  . c o m*/
    Sheet sheet = workbook.getSheetAt(0);
    SheetToJavaExecuter executer = new SheetToJavaExecuter();
    SheetData sheetData = new SheetData("SheetToJava");

    List<SheetToJavaParseInfo> sheet2JavaData = new ArrayList<SheetToJavaParseInfo>();
    List<SheetToJavaSettingInfo> sheet2JavaSettingData = new ArrayList<SheetToJavaSettingInfo>();

    // ===============================================
    // postParse( Sheet sheet, SheetParser sheetParser, SheetData sheetData)
    // ===============================================
    String sheetName = "testSheet";
    String tagName = "@SheetToJava";
    String settingTagName = tagName + "Setting";

    // SheetToJavaParseInfo
    SheetToJavaParseInfo parseInfo1 = new SheetToJavaParseInfo();
    parseInfo1.setSheetName(sheetName);
    parseInfo1.setLogicalNameRowNum(1);
    parseInfo1.setValueRowNum(2);
    parseInfo1.setSettingTagName(settingTagName);
    sheet2JavaData.add(parseInfo1);

    // SheetToJavaSettingInfo
    SheetToJavaSettingInfo settingInfo1 = new SheetToJavaSettingInfo();
    settingInfo1.setClazz(TestEntity1.class);
    settingInfo1.setPropertyName("propertyStr1");
    settingInfo1.setValue("@LNAME()");
    settingInfo1.setSheetName(sheetName);
    SheetToJavaSettingInfo settingInfo2 = new SheetToJavaSettingInfo();
    settingInfo2.setClazz(TestEntity1.class);
    settingInfo2.setPropertyName("propertyInt1");
    settingInfo2.setValue(10);
    settingInfo2.setSheetName(sheetName);
    sheet2JavaSettingData.add(settingInfo1);
    sheet2JavaSettingData.add(settingInfo2);

    // ???
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    // 
    SheetParser sheetParser = new SheetParser();
    sheetParser.addTagParser(new SheetToJavaParser());
    sheetParser.addTagParser(new SheetToJavaSettingParser());

    // No.1 postParse
    executer.postParse(sheet, sheetParser, sheetData);
    List<Object> results = (List<Object>) sheetData.get(tagName);
    assertEquals(3, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertEquals(new Integer(10), ((TestEntity1) results.get(0)).getPropertyInt1());
    assertEquals(new Integer(10), ((TestEntity1) results.get(1)).getPropertyInt1());
    assertEquals(new Integer(10), ((TestEntity1) results.get(2)).getPropertyInt1());

    // No.2 SheetToJavaSettingInfo????????
    assertNull(sheetData.get(settingTagName));

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    // No.3 ?null
    try {
        executer.postParse(null, sheetParser, sheetData);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.4 ?null
    try {
        executer.postParse(sheet, null, sheetData);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.5 ?null
    try {
        executer.postParse(sheet, sheetParser, null);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.6 ???
    sheetParser.addTagParser(new SheetToJavaParser("@UnusedSheetToJava")); /* ??? */
    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(3, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertEquals(new Integer(10), ((TestEntity1) results.get(0)).getPropertyInt1());
    assertEquals(new Integer(10), ((TestEntity1) results.get(1)).getPropertyInt1());
    assertEquals(new Integer(10), ((TestEntity1) results.get(2)).getPropertyInt1());

    // No.7 ?????
    SheetToJavaParseInfo parseInfo2 = new SheetToJavaParseInfo();
    parseInfo2.setSheetName("nonExistentSheet"); /* ????? */
    parseInfo2.setLogicalNameRowNum(1);
    parseInfo2.setValueRowNum(2);
    parseInfo2.setSettingTagName(settingTagName);
    sheet2JavaData.add(parseInfo2);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (ParseException pe) {
        // ?
        System.out.println("No.7:" + pe);
    }

    // No.8 ????null
    String sheetName2 = "testSheet (2)";
    SheetToJavaParseInfo parseInfo3 = new SheetToJavaParseInfo();
    parseInfo3.setSheetName(sheetName2);
    parseInfo3.setLogicalNameRowNum(1); /* null */
    parseInfo3.setValueRowNum(2);
    parseInfo3.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo3);

    SheetToJavaSettingInfo settingInfo3 = new SheetToJavaSettingInfo();
    settingInfo3.setClazz(TestEntity1.class);
    settingInfo3.setPropertyName("propertyInt1");
    settingInfo3.setValue("@LNAME()");
    settingInfo3.setSheetName(sheetName2);
    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo3);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (ParseException pe) {
        // ?
        System.out.println("No.8:" + pe);
    }

    // No.9 ?null
    SheetToJavaParseInfo parseInfo4 = new SheetToJavaParseInfo();
    parseInfo4.setSheetName(sheetName2);
    parseInfo4.setLogicalNameRowNum(2);
    parseInfo4.setValueRowNum(4); /* null */
    parseInfo4.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo4);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(1, results.size());
    assertEquals(new Integer(20), ((TestEntity1) results.get(0)).getPropertyInt1());

    // No.10 ?null?
    SheetToJavaParseInfo parseInfo5 = new SheetToJavaParseInfo();
    parseInfo5.setSheetName(sheetName2);
    parseInfo5.setLogicalNameRowNum(2);
    parseInfo5.setValueRowNum(3);
    parseInfo5.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo5);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(2, results.size());
    assertEquals(new Integer(10), ((TestEntity1) results.get(0)).getPropertyInt1());
    assertEquals(new Integer(20), ((TestEntity1) results.get(1)).getPropertyInt1());

    // No.11 ?null?
    String sheetName3 = "testSheet (3)";
    SheetToJavaParseInfo parseInfo6 = new SheetToJavaParseInfo();
    parseInfo6.setSheetName(sheetName3);
    parseInfo6.setLogicalNameRowNum(1);
    parseInfo6.setValueRowNum(2);
    parseInfo6.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo6);

    SheetToJavaSettingInfo settingInfo4 = new SheetToJavaSettingInfo();
    settingInfo4.setClazz(TestEntity1.class);
    settingInfo4.setPropertyName("propertyDate1");
    settingInfo4.setValue("@LNAME()");
    settingInfo4.setSheetName(sheetName3);
    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo4);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        results.clear();
        results = (List<Object>) sheetData.get(tagName);
        assertEquals(3, results.size());
        assertEquals(DateFormat.getDateInstance().parse("2009/1/1"),
                ((TestEntity1) results.get(0)).getPropertyDate1());
        assertNull(((TestEntity1) results.get(1)).getPropertyDate1());
        assertEquals(DateFormat.getDateInstance().parse("2009/2/1"),
                ((TestEntity1) results.get(2)).getPropertyDate1());
    } catch (RuntimeException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    // No.12 ????
    String sheetName4 = "testSheet (4)";
    SheetToJavaParseInfo parseInfo7 = new SheetToJavaParseInfo();
    parseInfo7.setSheetName(sheetName4);
    parseInfo7.setLogicalNameRowNum(1);
    parseInfo7.setValueRowNum(2);
    parseInfo7.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo7);

    SheetToJavaSettingInfo settingInfo5 = new SheetToJavaSettingInfo();
    settingInfo5.setClazz(TestEntity1.class);
    settingInfo5.setPropertyName("propertyDate1");
    settingInfo5.setValue("@LNAME(2009/1/1)");
    settingInfo5.setSheetName(sheetName4);
    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo5);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(0, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.12:" + pe);
    }

    // No.13 ???null
    String sheetName5 = "testSheet (5)";
    SheetToJavaParseInfo parseInfo8 = new SheetToJavaParseInfo();
    parseInfo8.setSheetName(sheetName5);
    // parseInfo8.setLogicalNameRowNum( 1);
    parseInfo8.setValueRowNum(2);
    parseInfo8.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo8);

    SheetToJavaSettingInfo settingInfo6 = new SheetToJavaSettingInfo();
    settingInfo6.setClazz(TestEntity1.class);
    settingInfo6.setPropertyName("propertyStr1");
    settingInfo6.setValue("@LNAME()");
    settingInfo6.setSheetName(sheetName5);
    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo6);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.14 ???No?null
    SheetToJavaParseInfo parseInfo9 = new SheetToJavaParseInfo();
    parseInfo9.setSheetName(sheetName5);
    // parseInfo9.setLogicalNameRowNum( 1);
    parseInfo9.setValueRowNum(2);
    parseInfo9.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo9);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.15 No?null
    SheetToJavaParseInfo parseInfo10 = new SheetToJavaParseInfo();
    parseInfo10.setSheetName(sheetName5);
    parseInfo10.setLogicalNameRowNum(1);
    // parseInfo10.setValueRowNum( 2);
    parseInfo10.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo10);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.16 Setting???null
    SheetToJavaParseInfo parseInfo11 = new SheetToJavaParseInfo();
    parseInfo11.setSheetName(sheetName5);
    parseInfo11.setLogicalNameRowNum(1);
    parseInfo11.setValueRowNum(2);
    // parseInfo11.setSettingTagName( settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo11);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    try {
        executer.postParse(sheet, sheetParser, sheetData);
        fail();
    } catch (NullPointerException e) {
        // ?
    }

    // No.17 SheetToJavaParseInfo??????
    sheet2JavaData.clear();

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(0, results.size());

    // No.18 SheetToJavaSettingInfo??????
    SheetToJavaParseInfo parseInfo12 = new SheetToJavaParseInfo();
    parseInfo12.setSheetName(sheetName5);
    parseInfo12.setLogicalNameRowNum(1);
    parseInfo12.setValueRowNum(2);
    parseInfo12.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo12);

    sheet2JavaSettingData.clear();

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(0, results.size());

    // No.19 ???
    String sheetName6 = "testSheet (6)";
    SheetToJavaParseInfo parseInfo13 = new SheetToJavaParseInfo();
    parseInfo13.setSheetName(sheetName6);
    parseInfo13.setLogicalNameRowNum(1);
    parseInfo13.setValueRowNum(2);
    parseInfo13.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo13);

    SheetToJavaSettingInfo settingInfo7 = new SheetToJavaSettingInfo();
    settingInfo7.setClazz(TestEntity1.class);
    settingInfo7.setPropertyName("propertyStr1");
    settingInfo7.setValue("@LNAME()");
    settingInfo7.setSheetName(sheetName6);
    settingInfo7.setUnique(true); /* ??? */
    SheetToJavaSettingInfo settingInfo8 = new SheetToJavaSettingInfo();
    settingInfo8.setClazz(TestEntity1.class);
    settingInfo8.setPropertyName("propertyInt1");
    settingInfo8.setValue("@LNAME()");
    settingInfo8.setUnique(true); /* ??? */
    settingInfo8.setSheetName(sheetName6);
    SheetToJavaSettingInfo settingInfo9 = new SheetToJavaSettingInfo();
    settingInfo9.setClazz(TestEntity1.class);
    settingInfo9.setPropertyName("propertyDate1");
    settingInfo9.setValue("@LNAME()");
    settingInfo9.setUnique(false); /* ?? */
    settingInfo9.setSheetName(sheetName6);

    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo7);
    sheet2JavaSettingData.add(settingInfo8);
    sheet2JavaSettingData.add(settingInfo9);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(3, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertEquals(new Integer(100), ((TestEntity1) results.get(0)).getPropertyInt1());
    assertNull(((TestEntity1) results.get(1)).getPropertyInt1());
    assertEquals(new Integer(300), ((TestEntity1) results.get(2)).getPropertyInt1());
    assertEquals(DateFormat.getDateInstance().parse("2009/1/1"),
            ((TestEntity1) results.get(0)).getPropertyDate1());
    assertEquals(DateFormat.getDateInstance().parse("2009/3/1"),
            ((TestEntity1) results.get(1)).getPropertyDate1());
    assertEquals(DateFormat.getDateInstance().parse("2009/4/1"),
            ((TestEntity1) results.get(2)).getPropertyDate1());

    // No.20 
    // TestEntity2??
    SheetToJavaSettingInfo settingInfo10 = new SheetToJavaSettingInfo();
    settingInfo10.setClazz(TestEntity2.class);
    settingInfo10.setPropertyName("propertyStr2");
    settingInfo10.setValue("@LNAME()");
    settingInfo10.setSheetName(sheetName6);
    settingInfo10.setUnique(true); /* ??? */
    SheetToJavaSettingInfo settingInfo11 = new SheetToJavaSettingInfo();
    settingInfo11.setClazz(TestEntity2.class);
    settingInfo11.setPropertyName("propertyInt2");
    settingInfo11.setValue("@LNAME()");
    settingInfo11.setUnique(false); /* ?? */
    settingInfo11.setSheetName(sheetName6);
    SheetToJavaSettingInfo settingInfo12 = new SheetToJavaSettingInfo();
    settingInfo12.setClazz(TestEntity2.class);
    settingInfo12.setPropertyName("propertyDate2");
    settingInfo12.setValue("@LNAME()");
    settingInfo12.setUnique(true); /* ??? */
    settingInfo12.setSheetName(sheetName6);

    // settingInfo10, 11, 12
    sheet2JavaSettingData.add(settingInfo10);
    sheet2JavaSettingData.add(settingInfo11);
    sheet2JavaSettingData.add(settingInfo12);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(7, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertEquals("String1", ((TestEntity2) results.get(3)).getPropertyStr2());
    assertEquals("String1", ((TestEntity2) results.get(4)).getPropertyStr2());
    assertEquals("String2", ((TestEntity2) results.get(5)).getPropertyStr2());
    assertEquals("String3", ((TestEntity2) results.get(6)).getPropertyStr2());
    assertEquals(new Integer(100), ((TestEntity1) results.get(0)).getPropertyInt1());
    assertNull(((TestEntity1) results.get(1)).getPropertyInt1());
    assertEquals(new Integer(300), ((TestEntity1) results.get(2)).getPropertyInt1());
    assertEquals(new Integer(100), ((TestEntity2) results.get(3)).getPropertyInt2());
    assertEquals(new Integer(100), ((TestEntity2) results.get(4)).getPropertyInt2());
    assertNull(((TestEntity2) results.get(5)).getPropertyInt2());
    assertEquals(new Integer(300), ((TestEntity2) results.get(6)).getPropertyInt2());
    assertEquals(DateFormat.getDateInstance().parse("2009/1/1"),
            ((TestEntity1) results.get(0)).getPropertyDate1());
    assertEquals(DateFormat.getDateInstance().parse("2009/3/1"),
            ((TestEntity1) results.get(1)).getPropertyDate1());
    assertEquals(DateFormat.getDateInstance().parse("2009/4/1"),
            ((TestEntity1) results.get(2)).getPropertyDate1());
    assertEquals(DateFormat.getDateInstance().parse("2009/1/1"),
            ((TestEntity2) results.get(3)).getPropertyDate2());
    assertEquals(DateFormat.getDateInstance().parse("2009/2/1"),
            ((TestEntity2) results.get(4)).getPropertyDate2());
    assertEquals(DateFormat.getDateInstance().parse("2009/3/1"),
            ((TestEntity2) results.get(5)).getPropertyDate2());
    assertEquals(DateFormat.getDateInstance().parse("2009/4/1"),
            ((TestEntity2) results.get(6)).getPropertyDate2());

    // ===============================================
    // addPropertyParser( SheetToJavaPropertyParser parser)
    // ===============================================
    // No.21 
    executer.addPropertyParser(new TestChildEntityParser());
    String sheetName7 = "testSheet (7)";
    SheetToJavaParseInfo parseInfo14 = new SheetToJavaParseInfo();
    parseInfo14.setSheetName(sheetName7);
    parseInfo14.setLogicalNameRowNum(1);
    parseInfo14.setValueRowNum(2);
    parseInfo14.setSettingTagName(settingTagName);
    sheet2JavaData.clear();
    sheet2JavaData.add(parseInfo14);

    SheetToJavaSettingInfo settingInfo13 = new SheetToJavaSettingInfo();
    settingInfo13.setClazz(TestEntity1.class);
    settingInfo13.setPropertyName("propertyStr1");
    settingInfo13.setValue("@LNAME()");
    settingInfo13.setSheetName(sheetName7);
    settingInfo13.setUnique(true); /* ??? */
    SheetToJavaSettingInfo settingInfo14 = new SheetToJavaSettingInfo();
    settingInfo14.setClazz(TestEntity1.class);
    settingInfo14.setPropertyName("child");
    settingInfo14.setValue("@TestChildEntity{childPropertyStr1=?1}");
    settingInfo14.setSheetName(sheetName7);

    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo13);
    sheet2JavaSettingData.add(settingInfo14);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(3, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertEquals("?1", ((TestEntity1) results.get(0)).getChild().getChildPropertyStr1());
    assertEquals("?1", ((TestEntity1) results.get(1)).getChild().getChildPropertyStr1());
    assertEquals("?1", ((TestEntity1) results.get(2)).getChild().getChildPropertyStr1());

    // No.22 ????
    SheetToJavaSettingInfo settingInfo15 = new SheetToJavaSettingInfo();
    settingInfo15.setClazz(TestEntity1.class);
    settingInfo15.setPropertyName("child");
    settingInfo15.setValue("@TestChildEntity{childPropertyStr1=@LNAME(?)}");
    settingInfo15.setSheetName(sheetName7);
    sheet2JavaSettingData.clear();
    sheet2JavaSettingData.add(settingInfo13);
    sheet2JavaSettingData.add(settingInfo15);

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(3, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertEquals("ChildString1", ((TestEntity1) results.get(0)).getChild().getChildPropertyStr1());
    assertEquals("ChildString3", ((TestEntity1) results.get(1)).getChild().getChildPropertyStr1());
    assertNull(((TestEntity1) results.get(2)).getChild().getChildPropertyStr1());

    // ===============================================
    // clearPropertyParsers()
    // ===============================================
    // No.23 
    executer.clearPropertyParsers();

    // ?
    sheetData = new SheetData("SheetToJava");
    sheetData.put(tagName, sheet2JavaData);
    sheetData.put(settingTagName, sheet2JavaSettingData);

    executer.postParse(sheet, sheetParser, sheetData);
    results.clear();
    results = (List<Object>) sheetData.get(tagName);
    assertEquals(3, results.size());
    assertEquals("String1", ((TestEntity1) results.get(0)).getPropertyStr1());
    assertEquals("String2", ((TestEntity1) results.get(1)).getPropertyStr1());
    assertEquals("String3", ((TestEntity1) results.get(2)).getPropertyStr1());
    assertNull(((TestEntity1) results.get(0)).getChild());
    assertNull(((TestEntity1) results.get(1)).getChild());
    assertNull(((TestEntity1) results.get(2)).getChild());
}

From source file:org.bbreak.excella.trans.tag.sheet2java.SheetToJavaParser.java

License:Open Source License

/**
 * ?//  ww  w .  j  a va 2  s  . c  o m
 * 
 * @param sheet 
 * @param tagCell ???
 * @param data TransProcessor?processBook, processSheet?<BR> 
 *              ????TagParser.parse??????<BR>
 * @return ?
 * @throws ParseException 
 */
@Override
public List<SheetToJavaParseInfo> parse(Sheet sheet, Cell tagCell, Object data) throws ParseException {
    // ?
    int tagRowIdx = tagCell.getRowIndex();
    int tagColIdx = tagCell.getColumnIndex();

    int valueRowFromIdx;
    int valueRowToIdx = sheet.getLastRowNum();

    // ????
    String settingTagName = getTag() + DEFAULT_SETTING_SUFFIX;

    try {
        Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue());

        // ?
        valueRowFromIdx = TagUtil.adjustValue(tagRowIdx, paramDef, PARAM_DATA_ROW_FROM,
                DEFAULT_DATA_ROW_FROM_ADJUST);
        if (valueRowFromIdx < 0 || valueRowFromIdx > sheet.getLastRowNum()) {
            throw new ParseException(tagCell, "?" + PARAM_DATA_ROW_FROM);
        }

        // ?
        valueRowToIdx = TagUtil.adjustValue(tagRowIdx, paramDef, PARAM_DATA_ROW_TO, valueRowToIdx - tagRowIdx);
        if (valueRowToIdx > sheet.getLastRowNum() || valueRowToIdx < 0) {
            throw new ParseException(tagCell, "?" + PARAM_DATA_ROW_TO);
        }

        // ???
        if (valueRowFromIdx > valueRowToIdx) {
            throw new ParseException(tagCell,
                    "?" + PARAM_DATA_ROW_FROM + "," + PARAM_DATA_ROW_TO);
        }

        // ????
        if (paramDef.containsKey(PARAM_SETTING_TAG_NAME)) {
            settingTagName = paramDef.get(PARAM_SETTING_TAG_NAME);
        }

        // ?
        if (paramDef.containsKey(PARAM_RESULT_KEY)) {
            // ???????
            throw new ParseException(tagCell, PARAM_RESULT_KEY + "????????");
        }

    } catch (Exception e) {
        if (e instanceof ParseException) {
            throw (ParseException) e;
        } else {
            throw new ParseException(tagCell, e);
        }
    }

    List<SheetToJavaParseInfo> sheetInfoList = new ArrayList<SheetToJavaParseInfo>();

    // ??
    int sheetNameColIdx = tagColIdx++;
    // ???No
    int logicalRowColIdx = tagColIdx++;
    // No
    int dataRowColIdx = tagColIdx;

    // ?????
    Workbook workbook = sheet.getWorkbook();

    // ???
    for (int rowNum = valueRowFromIdx; rowNum <= valueRowToIdx; rowNum++) {
        Row row = sheet.getRow(rowNum);
        if (row != null) {
            // ??
            Cell sheetNameCell = row.getCell(sheetNameColIdx);
            Cell logicalRowNumCell = row.getCell(logicalRowColIdx);
            Cell valueRowNumCell = row.getCell(dataRowColIdx);

            // ?
            if ((sheetNameCell == null) && (logicalRowNumCell == null) && (valueRowNumCell == null)) {
                // ????null??
                continue;

            } else if ((sheetNameCell == null) || (sheetNameCell.getStringCellValue() == null)
                    || ("".equals(sheetNameCell.getStringCellValue()))) {
                // ?????????
                continue;

            } else {
                // ????
                Cell requiredErrorCell = null;
                if (logicalRowNumCell == null) {
                    requiredErrorCell = row.createCell(logicalRowColIdx);
                } else if (valueRowNumCell == null) {
                    requiredErrorCell = row.createCell(dataRowColIdx);
                }

                // ??????
                if (requiredErrorCell != null) {
                    throw new ParseException(requiredErrorCell, "?null??");
                }
            }

            // ???No?
            int logicalRowNum;
            try {
                logicalRowNum = (Integer) PoiUtil.getCellValue(logicalRowNumCell, Integer.class);
            } catch (Exception e) {
                throw new ParseException(logicalRowNumCell, e);
            }

            // No?
            int valueRowNum;
            try {
                valueRowNum = (Integer) PoiUtil.getCellValue(valueRowNumCell, Integer.class);
            } catch (Exception e) {
                throw new ParseException(valueRowNumCell, e);
            }

            // ???
            String sheetName = sheetNameCell.getStringCellValue();
            if (workbook.getSheet(sheetName) == null) {
                throw new ParseException(sheetNameCell, "[" + sheetName + "]????");
            }

            // 
            SheetToJavaParseInfo sheetInfo = new SheetToJavaParseInfo();
            sheetInfo.setSettingTagName(settingTagName);
            sheetInfo.setSettingTagNameCell(tagCell);
            sheetInfo.setSheetName(sheetName);
            sheetInfo.setSheetNameCell(sheetNameCell);
            sheetInfo.setLogicalNameRowNum(logicalRowNum);
            sheetInfo.setLogicalNameRowNumCell(logicalRowNumCell);
            sheetInfo.setValueRowNum(valueRowNum);
            sheetInfo.setValueRowNumCell(valueRowNumCell);

            sheetInfoList.add(sheetInfo);
        }
    }

    return sheetInfoList;
}

From source file:org.bbreak.excella.trans.tag.sheet2java.SheetToJavaParserTest.java

License:Open Source License

@Test
public final void testSheetToJavaParser() throws ParseException {
    Workbook workbook = getWorkbook();//from ww  w. j  av a2 s.  c  o  m
    Sheet sheet1 = workbook.getSheetAt(0);
    Sheet sheet2 = workbook.getSheetAt(1);
    Sheet sheet3 = workbook.getSheetAt(2);
    Sheet sheet4 = workbook.getSheetAt(3);
    Sheet sheet5 = workbook.getSheetAt(4);
    String tag = "@SheetToJava";
    SheetToJavaParser parser = new SheetToJavaParser(tag);
    Cell tagCell = null;
    Object data = null;
    List<SheetToJavaParseInfo> list = null;

    // ===============================================
    // parse( Sheet sheet, Cell tagCell, Object data)
    // ===============================================
    // No.1 ?
    tagCell = sheet1.getRow(0).getCell(0);
    list = parser.parse(sheet1, tagCell, data);
    assertEquals(2, list.size());
    assertEquals(tag + "Setting", list.get(0).getSettingTagName());
    assertEquals(tag + "Setting", list.get(1).getSettingTagName());
    assertEquals("sheetName2", list.get(0).getSheetName());
    assertEquals("sheetName3", list.get(1).getSheetName());
    assertEquals(new Integer(2), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(3), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(5), list.get(0).getValueRowNum());
    assertEquals(new Integer(6), list.get(1).getValueRowNum());

    // No.2 
    tagCell = sheet1.getRow(0).getCell(4);
    list.clear();
    list = parser.parse(sheet1, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("@SettingTagName", list.get(0).getSettingTagName());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals(new Integer(7), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(8), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(10), list.get(0).getValueRowNum());
    assertEquals(new Integer(11), list.get(1).getValueRowNum());

    // No.3 ???null
    tagCell = sheet2.getRow(0).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("@SheetToJavaSetting", list.get(0).getSettingTagName());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals(new Integer(2), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(3), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(5), list.get(0).getValueRowNum());
    assertEquals(new Integer(6), list.get(1).getValueRowNum());

    // No.4 ???No?null
    tagCell = sheet2.getRow(8).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(11, cell.getRow().getRowNum());
        assertEquals(1, cell.getColumnIndex());
        System.out.println("No.4:" + pe);
    }

    // No.5 No?null
    tagCell = sheet2.getRow(16).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(20, cell.getRow().getRowNum());
        assertEquals(2, cell.getColumnIndex());
        System.out.println("No.5:" + pe);
    }

    // No.6 ?null
    tagCell = sheet2.getRow(24).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals(new Integer(17), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(18), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(19), list.get(0).getValueRowNum());
    assertEquals(new Integer(20), list.get(1).getValueRowNum());

    // No.7 ????null?
    tagCell = sheet2.getRow(32).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals(new Integer(21), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(22), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(23), list.get(0).getValueRowNum());
    assertEquals(new Integer(24), list.get(1).getValueRowNum());

    // No.8 ???No?
    tagCell = sheet2.getRow(40).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(42, cell.getRow().getRowNum());
        assertEquals(1, cell.getColumnIndex());
        System.out.println("No.8:" + pe);
    }

    // No.9 No?
    tagCell = sheet2.getRow(46).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(48, cell.getRow().getRowNum());
        assertEquals(2, cell.getColumnIndex());
        System.out.println("No.9:" + pe);
    }

    // No.10 
    tagCell = sheet3.getRow(5).getCell(0);
    list.clear();
    list = parser.parse(sheet3, tagCell, data);
    assertEquals(3, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("sheetName3", list.get(2).getSheetName());
    assertEquals(new Integer(1), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(2), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(3), list.get(2).getLogicalNameRowNum());
    assertEquals(new Integer(4), list.get(0).getValueRowNum());
    assertEquals(new Integer(5), list.get(1).getValueRowNum());
    assertEquals(new Integer(6), list.get(2).getValueRowNum());

    // No.11 DataRowFrom > DataRowTo
    tagCell = sheet3.getRow(9).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(9, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.11:" + pe);
    }

    // No.12 DataRowFrom??
    tagCell = sheet3.getRow(17).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(17, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.12:" + pe);
    }
    // No.13 DataRowTo??
    tagCell = sheet3.getRow(21).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(21, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.13:" + pe);
    }

    // No.14 SettingTagName??
    tagCell = sheet3.getRow(25).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(25, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.14:" + pe);
    }

    // No.15 ResultKey
    tagCell = sheet3.getRow(29).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(29, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.15:" + pe);
    }

    // No.16 DataRowFrom?1??
    tagCell = sheet4.getRow(0).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(0, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.16:" + pe);
    }

    // No.17 DataRowTo?1??
    tagCell = sheet4.getRow(0).getCell(4);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(0, cell.getRow().getRowNum());
        assertEquals(4, cell.getColumnIndex());
        System.out.println("No.17:" + pe);
    }

    // No.18 DataRowFrom???
    tagCell = sheet4.getRow(15).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(15, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.18:" + pe);
    }

    // No.19 DataRowTo???
    tagCell = sheet4.getRow(15).getCell(4);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(15, cell.getRow().getRowNum());
        assertEquals(4, cell.getColumnIndex());
        System.out.println("No.19:" + pe);
    }

    // No.20 
    parser = new SheetToJavaParser();
    tagCell = sheet1.getRow(0).getCell(0);
    list = parser.parse(sheet1, tagCell, data);
    assertEquals(2, list.size());
    assertEquals(tag + "Setting", list.get(0).getSettingTagName());
    assertEquals(tag + "Setting", list.get(1).getSettingTagName());
    assertEquals("sheetName2", list.get(0).getSheetName());
    assertEquals("sheetName3", list.get(1).getSheetName());
    assertEquals(new Integer(2), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(3), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(5), list.get(0).getValueRowNum());
    assertEquals(new Integer(6), list.get(1).getValueRowNum());

    // No.21 ?????
    tagCell = sheet5.getRow(0).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet5, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(4, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.21:" + pe);
    }

    // No.22 ???
    tagCell = sheet5.getRow(10).getCell(0);
    list.clear();
    list = parser.parse(sheet5, tagCell, data);
    assertEquals(2, list.size());
    assertEquals(tag + "Setting", list.get(0).getSettingTagName());
    assertEquals(tag + "Setting", list.get(1).getSettingTagName());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals(new Integer(4), list.get(0).getLogicalNameRowNum());
    assertEquals(new Integer(5), list.get(1).getLogicalNameRowNum());
    assertEquals(new Integer(7), list.get(0).getValueRowNum());
    assertEquals(new Integer(8), list.get(1).getValueRowNum());
}

From source file:org.bbreak.excella.trans.tag.sheet2java.SheetToJavaSettingParser.java

License:Open Source License

/**
 * ?// w  w w  .  j  av a  2  s  .c om
 * 
 * @param sheet 
 * @param tagCell ???
 * @param data TransProcessor?processBook, processSheet?<BR> 
 *              ????TagParser.parse??????<BR>
 * @return ?
 * @throws ParseException 
 */
@Override
public List<SheetToJavaSettingInfo> parse(Sheet sheet, Cell tagCell, Object data) throws ParseException {

    // ?
    int tagRowIdx = tagCell.getRowIndex();
    int tagColIdx = tagCell.getColumnIndex();

    // 
    int valueRowFromIdx;
    int valueRowToIdx = sheet.getLastRowNum();

    try {
        Map<String, String> paramDef = TagUtil.getParams(tagCell.getStringCellValue());

        // ?
        valueRowFromIdx = TagUtil.adjustValue(tagRowIdx, paramDef, PARAM_DATA_ROW_FROM,
                DEFAULT_DATA_ROW_FROM_ADJUST);
        if (valueRowFromIdx < 0 || valueRowFromIdx > sheet.getLastRowNum()) {
            throw new ParseException(tagCell, "?" + PARAM_DATA_ROW_FROM);
        }

        // ?
        valueRowToIdx = TagUtil.adjustValue(tagRowIdx, paramDef, PARAM_DATA_ROW_TO, valueRowToIdx - tagRowIdx);
        if (valueRowToIdx > sheet.getLastRowNum() || valueRowToIdx < 0) {
            throw new ParseException(tagCell, "?" + PARAM_DATA_ROW_TO);
        }

        // ???
        if (valueRowFromIdx > valueRowToIdx) {
            throw new ParseException(tagCell,
                    "?" + PARAM_DATA_ROW_FROM + "," + PARAM_DATA_ROW_TO);
        }

    } catch (Exception e) {
        if (e instanceof ParseException) {
            throw (ParseException) e;
        } else {
            throw new ParseException(tagCell, e);
        }
    }

    List<SheetToJavaSettingInfo> sheetSettingInfoList = new ArrayList<SheetToJavaSettingInfo>();

    // ??
    int sheetNameColIdx = tagColIdx++;
    // 
    int valueColIdx = tagColIdx++;
    // 
    int classColIdx = tagColIdx++;
    // 
    int propertyNameColIdx = tagColIdx++;
    // ?
    int uniqueColIdx = tagColIdx++;

    // ?????
    Workbook workbook = sheet.getWorkbook();

    // ???
    for (int rowNum = valueRowFromIdx; rowNum <= valueRowToIdx; rowNum++) {
        Row row = sheet.getRow(rowNum);
        if (row != null) {
            // ??
            Cell sheetNameCell = row.getCell(sheetNameColIdx);
            Cell valueCell = row.getCell(valueColIdx);
            Cell classCell = row.getCell(classColIdx);
            Cell propertyNameCell = row.getCell(propertyNameColIdx);
            Cell uniqueCell = row.getCell(uniqueColIdx);

            // ?
            if ((sheetNameCell == null) && (valueCell == null) && (classCell == null)
                    && (propertyNameCell == null) && (uniqueCell == null)) {
                // ????null??
                continue;

            } else if ((sheetNameCell == null) || (sheetNameCell.getStringCellValue() == null)
                    || ("".equals(sheetNameCell.getStringCellValue()))) {
                // ?????????
                continue;

            } else {
                // ????
                Cell requiredErrorCell = null;
                if (classCell == null) {
                    // ?null??
                    requiredErrorCell = row.createCell(classColIdx);
                }

                // ??
                if (requiredErrorCell != null) {
                    throw new ParseException(requiredErrorCell, "?null??");
                }
            }

            // ??
            SheetToJavaSettingInfo settingInfo = new SheetToJavaSettingInfo();

            // ????
            String sheetName = sheetNameCell.getStringCellValue();
            if (workbook.getSheet(sheetName) == null) {
                throw new ParseException(sheetNameCell, "[" + sheetName + "]????");
            }

            // ??
            settingInfo.setSheetName(sheetName);
            settingInfo.setSheetNameCell(sheetNameCell);

            // ?
            try {
                settingInfo.setClazz(Class.forName(classCell.getStringCellValue()));
                settingInfo.setClazzCell(classCell);
            } catch (ClassNotFoundException e) {
                throw new ParseException(classCell, e);
            }

            // 
            Object value = PoiUtil.getCellValue(valueCell);
            settingInfo.setValueCell(valueCell);

            // ?????
            boolean isValueTag = false;
            // ????????
            boolean isValueLogicalNameTag = false;
            if (value instanceof String) {
                // ??
                String valueStr = (String) value;
                if ((valueStr).startsWith(SheetToJavaExecuter.TAG_PREFIX)) {
                    // ??
                    isValueTag = true;
                    if ((valueStr).startsWith(SheetToJavaExecuter.TAG_LOGICAL_NAME_PREFIX)) {
                        // ?????
                        isValueLogicalNameTag = true;
                    }
                }
            }

            if (!isValueTag || isValueLogicalNameTag) {
                // ?????????

                // ??
                Cell requiredErrorCell = null;
                if (propertyNameCell == null) {
                    requiredErrorCell = row.createCell(propertyNameColIdx);
                }
                if (requiredErrorCell != null) {
                    throw new ParseException(requiredErrorCell, "?null??");
                }

                // ?
                settingInfo.setPropertyName(propertyNameCell.getStringCellValue());
                settingInfo.setPropertyNameCell(propertyNameCell);

                // ?
                Class<?> propertyClass = null;
                try {
                    Object obj = settingInfo.getClazz().newInstance();
                    propertyClass = PropertyUtils.getPropertyType(obj, settingInfo.getPropertyName());
                } catch (Exception e) {
                    throw new ParseException(propertyNameCell, e);
                }
                if (propertyClass == null) {
                    throw new ParseException(propertyNameCell,
                            "?:" + settingInfo.getPropertyName());
                }

                // ????
                if (uniqueCell != null) {
                    if (uniqueCell.getStringCellValue() != null
                            && uniqueCell.getStringCellValue().equals(UNIQUE_PROPERTY_MARK)) {
                        settingInfo.setUnique(true);
                        settingInfo.setUniqueCell(uniqueCell);
                    }
                }
            } else {
                // ??

                // ?????
                try {
                    TagUtil.getParams((String) value);
                } catch (Exception e) {
                    throw new ParseException(valueCell, e);
                }
            }

            // ??????
            boolean checkTypeFlag = false;
            if (value instanceof String) {
                if (!isValueTag) {
                    // ??
                    checkTypeFlag = true;
                }
            } else {
                // ??
                if (value != null) {
                    // null??
                    checkTypeFlag = true;
                }
            }

            // ?
            if (checkTypeFlag) {
                // ????
                Object obj;
                try {
                    obj = settingInfo.getClazz().newInstance();
                    Class<?> propertyClass = PropertyUtils.getPropertyType(obj, settingInfo.getPropertyName());
                    value = PoiUtil.getCellValue(valueCell, propertyClass);
                } catch (Exception e) {
                    throw new ParseException(valueCell, e);
                }
            }
            settingInfo.setValue(value);

            // ????
            sheetSettingInfoList.add(settingInfo);
        }
    }
    return sheetSettingInfoList;
}

From source file:org.bbreak.excella.trans.tag.sheet2java.SheetToJavaSettingParserTest.java

License:Open Source License

@Test
public final void testSheetToJavaSettingParser() throws ParseException {
    Workbook workbook = getWorkbook();//from w  ww  . ja  v a2 s.c o m
    Sheet sheet1 = workbook.getSheetAt(0);
    Sheet sheet2 = workbook.getSheetAt(1);
    Sheet sheet3 = workbook.getSheetAt(2);
    Sheet sheet4 = workbook.getSheetAt(3);
    Sheet sheet5 = workbook.getSheetAt(4);
    String tag = "@SheetToJavaSetting";
    SheetToJavaSettingParser parser = new SheetToJavaSettingParser(tag);
    Cell tagCell = null;
    Object data = null;
    List<SheetToJavaSettingInfo> list = null;

    // ===============================================
    // parse( Sheet sheet, Cell tagCell, Object data)
    // ===============================================
    // No.1 ?
    tagCell = sheet1.getRow(0).getCell(0);
    list = parser.parse(sheet1, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName2", list.get(0).getSheetName());
    assertEquals("sheetName3", list.get(1).getSheetName());
    assertEquals(2, list.get(0).getValue());
    assertEquals("value3", list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity2.class, list.get(1).getClazz());
    assertEquals("propertyInt1", list.get(0).getPropertyName());
    assertEquals("propertyStr2", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());

    // No.2 
    tagCell = sheet1.getRow(0).getCell(6);
    list.clear();
    list = parser.parse(sheet1, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("value4", list.get(0).getValue());
    assertEquals(5, list.get(1).getValue());
    assertEquals(TestEntity2.class, list.get(0).getClazz());
    assertEquals(TestEntity2.class, list.get(1).getClazz());
    assertEquals("propertyStr2", list.get(0).getPropertyName());
    assertEquals("propertyInt2", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertFalse(list.get(1).isUnique());

    // No.3 ???null
    tagCell = sheet2.getRow(0).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals(2, list.get(0).getValue());
    assertEquals("value3", list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity2.class, list.get(1).getClazz());
    assertEquals("propertyInt1", list.get(0).getPropertyName());
    assertEquals("propertyStr2", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());

    // No.4 ?null
    tagCell = sheet2.getRow(8).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(3, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("sheetName3", list.get(2).getSheetName());
    assertEquals("value4", list.get(0).getValue());
    assertNull(list.get(1).getValue());
    assertEquals("value5", list.get(2).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity1.class, list.get(1).getClazz());
    assertEquals(TestEntity2.class, list.get(2).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyInt1", list.get(1).getPropertyName());
    assertEquals("propertyStr2", list.get(2).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());
    assertTrue(list.get(2).isUnique());

    // No.5 ?null
    tagCell = sheet2.getRow(16).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(20, cell.getRow().getRowNum());
        assertEquals(2, cell.getColumnIndex());
        System.out.println("No.5:" + pe);
    }

    // No.6 ?null
    tagCell = sheet2.getRow(24).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(26, cell.getRow().getRowNum());
        assertEquals(3, cell.getColumnIndex());
        System.out.println("No.6:" + pe);
    }

    // No.7 ????null
    tagCell = sheet2.getRow(32).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(3, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("sheetName3", list.get(2).getSheetName());
    assertEquals("value12", list.get(0).getValue());
    assertEquals(13, list.get(1).getValue());
    assertEquals("value14", list.get(2).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity1.class, list.get(1).getClazz());
    assertEquals(TestEntity2.class, list.get(2).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyInt1", list.get(1).getPropertyName());
    assertEquals("propertyStr2", list.get(2).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertFalse(list.get(1).isUnique());
    assertTrue(list.get(2).isUnique());

    // No.8 ?null
    tagCell = sheet2.getRow(40).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("value15", list.get(0).getValue());
    assertEquals("value16", list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity2.class, list.get(1).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyStr2", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertFalse(list.get(1).isUnique());

    // No.9 ????null?
    tagCell = sheet2.getRow(48).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("value17", list.get(0).getValue());
    assertEquals("value18", list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity2.class, list.get(1).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyStr2", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertFalse(list.get(1).isUnique());

    // No.10 ????
    tagCell = sheet2.getRow(56).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(1, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("@LNAME(1)", list.get(0).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertFalse(list.get(0).isUnique());

    // No.11 ??????null
    tagCell = sheet2.getRow(62).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(64, cell.getRow().getRowNum());
        assertEquals(3, cell.getColumnIndex());
        System.out.println("No.11:" + pe);
    }

    // No.12 ?
    tagCell = sheet2.getRow(68).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(1, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals(
            "@TestChildEntity{childPropertyStr1=@LNAME(?1),childPropertyInt1=@LNAME(?1)}",
            list.get(0).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertNull(list.get(0).getPropertyName());
    assertFalse(list.get(0).isUnique());

    // No.13 ???null
    tagCell = sheet2.getRow(74).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(1, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals(
            "@TestChildEntity{childPropertyStr1=@LNAME(?1),childPropertyInt1=@LNAME(?1)}",
            list.get(0).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertNull(list.get(0).getPropertyName());
    assertFalse(list.get(0).isUnique());

    // No.14 ??????
    tagCell = sheet2.getRow(80).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(1, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals(
            "@TestChildEntity{childPropertyStr1=@LNAME(?1),childPropertyInt1=@LNAME(?1)}",
            list.get(0).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertNull(list.get(0).getPropertyName());
    assertFalse(list.get(0).isUnique());

    // No.15 ????
    tagCell = sheet2.getRow(86).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(88, cell.getRow().getRowNum());
        assertEquals(1, cell.getColumnIndex());
    }

    // No.16 ?
    tagCell = sheet2.getRow(92).getCell(0);
    list.clear();
    list = parser.parse(sheet2, tagCell, data);
    assertEquals(1, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("10", list.get(0).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertFalse(list.get(0).isUnique());

    // No.17 ?
    tagCell = sheet2.getRow(98).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(100, cell.getRow().getRowNum());
        assertEquals(1, cell.getColumnIndex());
        System.out.println("No.17:" + pe);
    }

    // No.18 ?
    tagCell = sheet2.getRow(104).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(106, cell.getRow().getRowNum());
        assertEquals(1, cell.getColumnIndex());
        System.out.println("No.18:" + pe);
    }

    // No.19 ???
    tagCell = sheet2.getRow(110).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(112, cell.getRow().getRowNum());
        assertEquals(2, cell.getColumnIndex());
        System.out.println("No.19:" + pe);
    }

    // No.20 ???
    tagCell = sheet2.getRow(116).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(118, cell.getRow().getRowNum());
        assertEquals(3, cell.getColumnIndex());
        System.out.println("No.20:" + pe);
    }

    // No.21 ?
    tagCell = sheet2.getRow(122).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet2, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(124, cell.getRow().getRowNum());
        assertEquals(3, cell.getColumnIndex());
        System.out.println("No.21:" + pe);
    }

    // No.22 
    tagCell = sheet3.getRow(5).getCell(0);
    list.clear();
    list = parser.parse(sheet3, tagCell, data);
    assertEquals(3, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("sheetName3", list.get(2).getSheetName());
    assertEquals("value1", list.get(0).getValue());
    assertEquals(2, list.get(1).getValue());
    assertEquals("value3", list.get(2).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity1.class, list.get(1).getClazz());
    assertEquals(TestEntity2.class, list.get(2).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyInt1", list.get(1).getPropertyName());
    assertEquals("propertyStr2", list.get(2).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());
    assertTrue(list.get(2).isUnique());

    // No.23 DataRowFrom > DataRowTo
    tagCell = sheet3.getRow(9).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(9, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.23:" + pe);
    }

    // No.24 DataRowFrom??
    tagCell = sheet3.getRow(17).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(17, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.24:" + pe);
    }

    // No.25 DataRowTo??
    tagCell = sheet3.getRow(21).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet3, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(21, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.25:" + pe);
    }

    // No.26 ResultKey
    tagCell = sheet3.getRow(25).getCell(0);
    list.clear();
    list = parser.parse(sheet3, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("value7", list.get(0).getValue());
    assertEquals(8, list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity1.class, list.get(1).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyInt1", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());

    // No.27 DataRowFrom?1??
    tagCell = sheet4.getRow(0).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(0, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.27:" + pe);
    }

    // No.28 DataRowTo?1??
    tagCell = sheet4.getRow(0).getCell(4);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(0, cell.getRow().getRowNum());
        assertEquals(4, cell.getColumnIndex());
        System.out.println("No.28:" + pe);
    }

    // No.29 DataRowFrom???
    tagCell = sheet4.getRow(15).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(15, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.29:" + pe);
    }

    // No.30 DataRowTo???
    tagCell = sheet4.getRow(15).getCell(4);
    list.clear();
    try {
        list = parser.parse(sheet4, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(15, cell.getRow().getRowNum());
        assertEquals(4, cell.getColumnIndex());
        System.out.println("No.30:" + pe);
    }

    // No.31 
    parser = new SheetToJavaSettingParser();
    tagCell = sheet1.getRow(0).getCell(0);
    list = parser.parse(sheet1, tagCell, data);
    assertEquals(2, list.size());
    assertEquals("sheetName2", list.get(0).getSheetName());
    assertEquals("sheetName3", list.get(1).getSheetName());
    assertEquals(2, list.get(0).getValue());
    assertEquals("value3", list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity2.class, list.get(1).getClazz());
    assertEquals("propertyInt1", list.get(0).getPropertyName());
    assertEquals("propertyStr2", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());

    // No.32 ?????
    tagCell = sheet5.getRow(0).getCell(0);
    list.clear();
    try {
        list = parser.parse(sheet5, tagCell, data);
        fail();
    } catch (ParseException pe) {
        Cell cell = pe.getCell();
        assertEquals(4, cell.getRow().getRowNum());
        assertEquals(0, cell.getColumnIndex());
        System.out.println("No.21:" + pe);
    }

    // No.33 ???
    tagCell = sheet5.getRow(10).getCell(0);
    list.clear();
    list = parser.parse(sheet5, tagCell, data);
    assertEquals(2, list.size());
    assertEquals(2, list.size());
    assertEquals("sheetName1", list.get(0).getSheetName());
    assertEquals("sheetName2", list.get(1).getSheetName());
    assertEquals("value4", list.get(0).getValue());
    assertEquals(5, list.get(1).getValue());
    assertEquals(TestEntity1.class, list.get(0).getClazz());
    assertEquals(TestEntity1.class, list.get(1).getClazz());
    assertEquals("propertyStr1", list.get(0).getPropertyName());
    assertEquals("propertyInt1", list.get(1).getPropertyName());
    assertTrue(list.get(0).isUnique());
    assertTrue(list.get(1).isUnique());
}