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

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

Introduction

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

Prototype

int getFirstRowNum();

Source Link

Document

Gets the first row on the sheet.

Usage

From source file:org.smart.migrate.util.ExcelUtils.java

/**
 * Add indendity column data for excel sheet
 * @param filename Excel name// www .  j  a v a2s  . c  o m
 * @param sheetName Sheet name
 */
public static void addIndendityColumnData(String filename, String sheetName) {
    try {
        InputStream inp = new FileInputStream(filename);
        Workbook wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheet(sheetName);
        if (sheet != null && sheet.getPhysicalNumberOfRows() > 0) {
            Row row = sheet.getRow(sheet.getFirstRowNum());

            if (row != null) {
                int idColumn = cellIndexInRow("id", row);
                if (idColumn == -1) {
                    idColumn = row.getLastCellNum();
                    row.createCell(idColumn).setCellValue("id");
                    for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                        Row r = sheet.getRow(i);
                        Cell cell = r.getCell(idColumn);
                        if (cell == null) {
                            cell = r.createCell(idColumn);
                        }
                        cell.setCellValue(i);
                    }
                    FileOutputStream fileOut = new FileOutputStream(filename);
                    wb.write(fileOut);
                    fileOut.close();
                }
                inp.close();
            }
        }

    } catch (IOException ex) {
        Logger.getLogger(MetaExcelDao.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvalidFormatException ex) {
        Logger.getLogger(MetaExcelDao.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.spionen.james.jamesfile.ExcelJamesFile.java

License:Open Source License

public Map<Long, Subscriber> readFile(File file) throws IOException {
    Map<Long, Subscriber> subscribers = new TreeMap<Long, Subscriber>();
    try {//from   ww w . j  a  v a  2s. co m
        Workbook wb = WorkbookFactory.create(file);
        Sheet s = wb.getSheetAt(0);

        // Take first row, use to check order of fields
        Row firstRow = s.getRow(s.getFirstRowNum());
        FieldType[] order = new FieldType[firstRow.getLastCellNum() - firstRow.getFirstCellNum()];
        int j = 0;
        for (int i = firstRow.getFirstCellNum(); i < firstRow.getLastCellNum(); i++, j++) {
            Cell c = firstRow.getCell(i);
            if (c != null) {
                if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                    String val = new Integer(new Double(c.getNumericCellValue()).intValue()).toString();
                    order[j] = FieldType.getFieldType(val);
                } else {
                    order[j] = FieldType.getFieldType(c.getStringCellValue());
                }
            }
        }
        // Then iterate through the rest of the rows
        if (s.getLastRowNum() > 0) {
            // LastRowNum is 0-indexed, so add 1
            for (int i = s.getFirstRowNum() + 1; i < s.getLastRowNum() + 1; i++) {
                Row r = s.getRow(i);
                Subscriber sub = new Subscriber();
                j = 0;
                // LastCellNum is also 0-indexed
                for (int k = r.getFirstCellNum(); k < r.getLastCellNum() + 1; k++, j++) {
                    Cell c = r.getCell(k);
                    if (c != null) {
                        if (c.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                            String val = new Integer(new Double(c.getNumericCellValue()).intValue()).toString();
                            sub.setByField(order[j], val);
                        } else {
                            sub.setByField(order[j], c.getStringCellValue());
                        }
                    }
                }
                subscribers.put(sub.getAbNr(), sub);
            }
        }
        return subscribers;
    } catch (InvalidFormatException ife) {
        // If the file was badly formatted
        throw new IOException(ife);
    }
}

From source file:org.talend.dataprep.schema.xls.XlsSchemaParser.java

License:Open Source License

/**
 * We store (cell types per row) per column.
 *
 * @param sheet key is the column number, value is a Map with key row number and value Type
 * @return A Map&lt;colId, Map&lt;rowId, type&gt;&gt;
 *///  ww w. j a  va  2s.  co  m
private SortedMap<Integer, SortedMap<Integer, String>> collectSheetTypeMatrix(Sheet sheet,
        FormulaEvaluator formulaEvaluator) {

    int firstRowNum = sheet.getFirstRowNum();
    int lastRowNum = sheet.getLastRowNum();

    LOGGER.debug("firstRowNum: {}, lastRowNum: {}", firstRowNum, lastRowNum);

    SortedMap<Integer, SortedMap<Integer, String>> cellsTypeMatrix = new TreeMap<>();

    // we start analysing rows
    for (int rowCounter = firstRowNum; rowCounter <= lastRowNum; rowCounter++) {

        int cellCounter = 0;

        Row row = sheet.getRow(rowCounter);
        if (row == null) {
            continue;
        }

        Iterator<Cell> cellIterator = row.cellIterator();

        String currentType;

        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();

            int xlsType = Cell.CELL_TYPE_STRING;

            try {
                xlsType = cell.getCellType() == Cell.CELL_TYPE_FORMULA ? //
                        formulaEvaluator.evaluate(cell).getCellType() : cell.getCellType();
            } catch (Exception e) {
                // ignore formula error evaluation get as a String with the formula
            }
            switch (xlsType) {
            case Cell.CELL_TYPE_BOOLEAN:
                currentType = BOOLEAN.getName();
                break;
            case Cell.CELL_TYPE_NUMERIC:
                currentType = getTypeFromNumericCell(cell);
                break;
            case Cell.CELL_TYPE_BLANK:
                currentType = BLANK;
                break;
            case Cell.CELL_TYPE_FORMULA:
            case Cell.CELL_TYPE_STRING:
                currentType = STRING.getName();
                break;
            case Cell.CELL_TYPE_ERROR:
                // we cannot really do anything with an error
            default:
                currentType = ANY.getName();
            }

            SortedMap<Integer, String> cellInfo = cellsTypeMatrix.get(cellCounter);

            if (cellInfo == null) {
                cellInfo = new TreeMap<>();
            }
            cellInfo.put(rowCounter, currentType);

            cellsTypeMatrix.put(cellCounter, cellInfo);
            cellCounter++;
        }
    }

    LOGGER.trace("cellsTypeMatrix: {}", cellsTypeMatrix);
    return cellsTypeMatrix;
}

From source file:org.talend.dataprep.transformation.format.XlsWriterTest.java

License:Open Source License

@Test
public void write_simple_xls_file() throws Exception {
    // given/*from  w  w w. j ava2 s  .co  m*/
    SchemaParser.Request request = createSchemaParser("export_dataset.json");

    Workbook workbook = WorkbookFactory.create(request.getContent());
    assertThat(workbook).isNotNull();
    assertThat(workbook.getNumberOfSheets()).isEqualTo(1);

    Sheet sheet = workbook.getSheetAt(0);
    assertThat(sheet).isNotNull().isNotEmpty();
    assertThat(sheet.getFirstRowNum()).isEqualTo(0);
    assertThat(sheet.getLastRowNum()).isEqualTo(6);

    // assert header content
    Row row = sheet.getRow(0);
    /*
     * "columns": [ { "id": "id", "type": "string" }, { "id": "firstname", "type": "string" }, { "id": "lastname",
     * "type": "string" }, { "id": "age", "type": "integer" }, { "id": "date-of-birth", "type": "date" }, { "id":
     * "alive", "type": "boolean" }, { "id": "city", "type": "string" } ]
     */
    assertThat(row.getCell(0).getRichStringCellValue().getString()).isEqualTo("id");
    assertThat(row.getCell(1).getRichStringCellValue().getString()).isEqualTo("firstname");
    assertThat(row.getCell(2).getRichStringCellValue().getString()).isEqualTo("lastname");
    assertThat(row.getCell(3).getRichStringCellValue().getString()).isEqualTo("age");
    assertThat(row.getCell(4).getRichStringCellValue().getString()).isEqualTo("date-of-birth");
    assertThat(row.getCell(5).getRichStringCellValue().getString()).isEqualTo("alive");
    assertThat(row.getCell(6).getRichStringCellValue().getString()).isEqualTo("city");

    // assert first content
    row = sheet.getRow(1);
    /*
     * { "id" : "1", "firstname" : "Clark", "lastname" : "Kent", "age" : "42", "date-of-birth" : "10/09/1940",
     * "alive" : "false", "city" : "Smallville" }
     */

    assertThat(row.getCell(0).getNumericCellValue()).isEqualTo(1);
    assertThat(row.getCell(1).getStringCellValue()).isEqualTo("Clark");
    assertThat(row.getCell(2).getStringCellValue()).isEqualTo("Kent");
    assertThat(row.getCell(3).getNumericCellValue()).isEqualTo((double) 42);
    assertThat(row.getCell(4).getStringCellValue()).isEqualTo("10/09/1940");
    assertThat(row.getCell(5).getBooleanCellValue()).isFalse();
    assertThat(row.getCell(6).getStringCellValue()).isEqualTo("Smallville");

    // assert last content
    row = sheet.getRow(sheet.getLastRowNum());
    /*
     * { "id" : "6", "firstname" : "Ray", "lastname" : "Palmer", "age" : "93", "date-of-birth" : "01/05/1951",
     * "alive" : "true", "city" : "Star city" }
     */
    assertThat(row.getCell(0).getNumericCellValue()).isEqualTo(6);
    assertThat(row.getCell(1).getStringCellValue()).isEqualTo("Ray");
    assertThat(row.getCell(2).getStringCellValue()).isEqualTo("Palmer");
    assertThat(row.getCell(3).getNumericCellValue()).isEqualTo((double) 93);
    assertThat(row.getCell(4).getStringCellValue()).isEqualTo("01/05/1951");
    assertThat(row.getCell(5).getBooleanCellValue()).isTrue();
    assertThat(row.getCell(6).getStringCellValue()).isEqualTo("Star city");
}

From source file:org.talend.dataprep.transformation.format.XlsWriterTest.java

License:Open Source License

/**
 * Please have a look at <a href="https://jira.talendforge.org/browse/TDP-1528">TDP-1528</a>.
 *//*from www  .  jav  a  2 s  .co m*/
@Test
public void TDP_1528_export_of_backslash() throws Exception {

    // given
    SchemaParser.Request request = createSchemaParser("tdp_1528_backslash_not_exported.json");

    Workbook workbook = WorkbookFactory.create(request.getContent());
    assertThat(workbook).isNotNull();
    assertThat(workbook.getNumberOfSheets()).isEqualTo(1);

    Sheet sheet = workbook.getSheetAt(0);
    assertThat(sheet).isNotNull().isNotEmpty();
    assertThat(sheet.getFirstRowNum()).isEqualTo(0);
    assertThat(sheet.getLastRowNum()).isEqualTo(2);

    // assert header content
    Row row = sheet.getRow(0);
    /*
     * [ {"id": "0", "name": "column1", "type": "string"}, {"id": "1", "name": "column2", "type": "string"},
     * {"id": "2", "name": "column2", "type": "string"} ]
     */
    assertThat(row.getCell(0).getRichStringCellValue().getString()).isEqualTo("column1");
    assertThat(row.getCell(1).getRichStringCellValue().getString()).isEqualTo("column2");
    assertThat(row.getCell(2).getRichStringCellValue().getString()).isEqualTo("column3");

    // assert first content
    row = sheet.getRow(1);
    /*
     * { "0": "BEAUTIFUL ITEM DESC W\BAG", "1": "Hello", "2": "Yo" }
     */

    assertThat(row.getCell(0).getStringCellValue()).isEqualTo("BEAUTIFUL ITEM DESC W\\BAG");
    assertThat(row.getCell(1).getStringCellValue()).isEqualTo("Hello");
    assertThat(row.getCell(2).getStringCellValue()).isEqualTo("Yo");

    // assert last content
    row = sheet.getRow(sheet.getLastRowNum());
    /*
     * { "0": "Konishiwa", "1": "Na nga def", "2": "Hola" }
     */
    assertThat(row.getCell(0).getStringCellValue()).isEqualTo("Konishiwa");
    assertThat(row.getCell(1).getStringCellValue()).isEqualTo("Na nga def");
    assertThat(row.getCell(2).getStringCellValue()).isEqualTo("Hola");
}

From source file:org.talend.dataprep.transformation.format.XlsWriterTest.java

License:Open Source License

/**
 * Please have a look at <a href="https://jira.talendforge.org/browse/TDP-4571">TDP-4571</a>.
 *//*from w w w .j  a va2  s.  c om*/
@Test
public void export_bugfix() throws Exception {
    // given
    SchemaParser.Request request = createSchemaParser("export_bug_fix_xlsx.json");

    Workbook workbook = WorkbookFactory.create(request.getContent());
    assertThat(workbook).isNotNull();
    assertThat(workbook.getNumberOfSheets()).isEqualTo(1);

    Sheet sheet = workbook.getSheetAt(0);
    assertThat(sheet).isNotNull().isNotEmpty();
    assertThat(sheet.getFirstRowNum()).isEqualTo(0);
    assertThat(sheet.getLastRowNum()).isEqualTo(6);

    // assert header content
    Row row = sheet.getRow(0);
    /*
     * "columns": [ { "id": "id", "type": "string" }, { "id": "firstname", "type": "string" }, { "id": "lastname",
     * "type": "string" }, { "id": "age", "type": "integer" }, { "id": "date-of-birth", "type": "date" }, { "id":
     * "alive", "type": "boolean" }, { "id": "city", "type": "string" }, { "id": "7", "type": "float" } ]
     */
    assertThat(row.getCell(0).getRichStringCellValue().getString()).isEqualTo("id");
    assertThat(row.getCell(1).getRichStringCellValue().getString()).isEqualTo("firstname");
    assertThat(row.getCell(2).getRichStringCellValue().getString()).isEqualTo("lastname");
    assertThat(row.getCell(3).getRichStringCellValue().getString()).isEqualTo("age");
    assertThat(row.getCell(4).getRichStringCellValue().getString()).isEqualTo("date-of-birth");
    assertThat(row.getCell(5).getRichStringCellValue().getString()).isEqualTo("alive");
    assertThat(row.getCell(6).getRichStringCellValue().getString()).isEqualTo("city");
    assertThat(row.getCell(7).getRichStringCellValue().getString()).isEqualTo("phone-number");

    // assert first content
    row = sheet.getRow(1);
    /*
     * { "id" : "1", "firstname" : "Clark", "lastname" : "Kent", "age" : "42", "date-of-birth" : "10/09/1940",
     * "alive" : "false", "city" : "", "phone-number" : "" }
     */

    assertRowValues(row, 1, "Clark", "Kent", 42, "10/09/1940", //
            false, "Smallville", "");

    // assert second row content
    row = sheet.getRow(2);
    /*
     * { "id" : "2", "firstname" : "Bruce", "lastname" : "Wayne", "age" : "50", "date-of-birth" : "01/01/1947",
     * "alive" : "true", "city" : "Gotham city", "phone-number" : "null" }
     */
    assertRowValues(row, 2, "Bruce", "Wayne", 50, "01/01/1947", //
            true, "Gotham city", "null");

    // assert third row content
    row = sheet.getRow(3);
    /*
     * { "id" : "3", "firstname" : "Barry", "lastname" : "Allen", "age" : "67", "date-of-birth" : "01/02/1948",
     * "alive" : "true", "city" : "Central city", "phone-number" : "+33 6 89 46 55 34" }
     */
    assertRowValues(row, 3, "Barry", "Allen", 67, "01/02/1948", //
            true, "Central city", "+33 6 89 46 55 34");

    // assert last content
    row = sheet.getRow(sheet.getLastRowNum());
    /*
     * { "id" : "6", "firstname" : "Ray", "lastname" : "Palmer", "age" : "93", "date-of-birth" : "01/05/1951",
     * "alive" : "true", "city" : "Star city" }
     */
    assertRowValues(row, 6, "Ray", "Palmer", 93, "01/05/1951", //
            true, "Star city", "+33-6-89-46-55-34");
}

From source file:org.teiid.translator.excel.ExcelMetadataProcessor.java

License:Open Source License

private void addTable(MetadataFactory mf, Sheet sheet, String xlsName) {
    int firstRowNumber = sheet.getFirstRowNum();
    Row headerRow = null;/*from   ww w  .  java  2  s  .  c  o  m*/
    int firstCellNumber = -1;
    if (this.hasHeader) {
        headerRow = sheet.getRow(this.headerRowNumber);
        if (headerRow != null) {
            firstRowNumber = this.headerRowNumber;
            firstCellNumber = headerRow.getFirstCellNum();
            if (firstCellNumber == -1) {
                LogManager.logInfo(LogConstants.CTX_CONNECTOR,
                        ExcelPlugin.Util.gs(ExcelPlugin.Event.TEIID23006, xlsName));
                return;
            }
        }
    }

    if (headerRow == null) {
        while (firstCellNumber == -1) {
            headerRow = sheet.getRow(firstRowNumber++);
            // check if this is a empty sheet; the data must be present in first 10000 rows
            if (headerRow == null && firstRowNumber > 10000) {
                return;
            }
            if (headerRow == null) {
                continue;
            }
            firstCellNumber = headerRow.getFirstCellNum();
        }
    }

    // create a table for each sheet
    AtomicInteger columnCount = new AtomicInteger();
    Table table = mf.addTable(sheet.getSheetName());
    table.setNameInSource(sheet.getSheetName());
    table.setProperty(ExcelMetadataProcessor.FILE, xlsName);

    // add implicit row_id column based on row number from excel sheet 
    Column column = mf.addColumn(ROW_ID, TypeFacility.RUNTIME_NAMES.INTEGER, table);
    column.setSearchType(SearchType.All_Except_Like);
    column.setProperty(CELL_NUMBER, ROW_ID);
    mf.addPrimaryKey("PK0", Arrays.asList(ROW_ID), table); //$NON-NLS-1$
    column.setUpdatable(false);

    Row dataRow = null;
    int lastCellNumber = headerRow.getLastCellNum();

    if (this.hasDataRowNumber) {
        // adjust for zero index
        table.setProperty(ExcelMetadataProcessor.FIRST_DATA_ROW_NUMBER, String.valueOf(this.dataRowNumber + 1));
        dataRow = sheet.getRow(this.dataRowNumber);
    } else if (this.hasHeader) {
        // +1 zero based, +1 to skip header
        table.setProperty(ExcelMetadataProcessor.FIRST_DATA_ROW_NUMBER, String.valueOf(firstRowNumber + 2));
        dataRow = sheet.getRow(firstRowNumber + 1);
    } else {
        //+1 already occurred because of the increment above
        table.setProperty(ExcelMetadataProcessor.FIRST_DATA_ROW_NUMBER, String.valueOf(firstRowNumber));
        dataRow = sheet.getRow(firstRowNumber);
    }

    if (firstCellNumber != -1) {
        for (int j = firstCellNumber; j < lastCellNumber; j++) {
            Cell headerCell = headerRow.getCell(j);
            Cell dataCell = dataRow.getCell(j);
            // if the cell value is null; then advance the data row cursor to to find it 
            if (dataCell == null) {
                for (int rowNo = firstRowNumber + 1; rowNo < firstRowNumber + 10000; rowNo++) {
                    Row row = sheet.getRow(rowNo);
                    dataCell = row.getCell(j);
                    if (dataCell != null) {
                        break;
                    }
                }
            }
            column = mf.addColumn(cellName(headerCell, columnCount), cellType(headerCell, dataCell), table);
            column.setSearchType(SearchType.Unsearchable);
            column.setProperty(ExcelMetadataProcessor.CELL_NUMBER, String.valueOf(j + 1));
        }
    }
}

From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java

License:MIT License

/**
 * Gets the sheet configuration./*from  w w  w . j av  a 2 s  .  c  o m*/
 *
 * @param sheet
 *            the sheet
 * @param formName
 *            the form name
 * @param sheetRightCol
 *            the sheet right col
 * @return the sheet configuration
 */
private SheetConfiguration getSheetConfiguration(final Sheet sheet, final String formName,
        final int sheetRightCol) {

    SheetConfiguration sheetConfig = new SheetConfiguration();
    sheetConfig.setFormName(formName);
    sheetConfig.setSheetName(sheet.getSheetName());
    int leftCol = sheet.getLeftCol();
    int lastRow = sheet.getLastRowNum();
    int firstRow = sheet.getFirstRowNum();
    int rightCol = 0;
    int maxRow = 0;
    for (Row row : sheet) {
        if (row.getRowNum() > TieConstants.TIE_WEB_SHEET_MAX_ROWS) {
            break;
        }
        maxRow = row.getRowNum();
        int firstCellNum = row.getFirstCellNum();
        if (firstCellNum >= 0 && firstCellNum < leftCol) {
            leftCol = firstCellNum;
        }
        if ((row.getLastCellNum() - 1) > rightCol) {
            int verifiedcol = verifyLastCell(row, rightCol, sheetRightCol);
            if (verifiedcol > rightCol) {
                rightCol = verifiedcol;
            }
        }
    }
    if (maxRow < lastRow) {
        lastRow = maxRow;
    }
    // header range row set to 0 while column set to first column to
    // max
    // column (FF) e.g. $A$0 : $FF$0
    String tempStr = TieConstants.CELL_ADDR_PRE_FIX + WebSheetUtility.getExcelColumnName(leftCol)
            + TieConstants.CELL_ADDR_PRE_FIX + "0 : " + TieConstants.CELL_ADDR_PRE_FIX
            + WebSheetUtility.getExcelColumnName(rightCol) + TieConstants.CELL_ADDR_PRE_FIX + "0";
    sheetConfig.setFormHeaderRange(tempStr);
    sheetConfig.setHeaderCellRange(new CellRange(tempStr));
    // body range row set to first row to last row while column set
    // to
    // first column to max column (FF) e.g. $A$1 : $FF$1000
    tempStr = TieConstants.CELL_ADDR_PRE_FIX + WebSheetUtility.getExcelColumnName(leftCol)
            + TieConstants.CELL_ADDR_PRE_FIX + (firstRow + 1) + " : " + TieConstants.CELL_ADDR_PRE_FIX
            + WebSheetUtility.getExcelColumnName(rightCol) + TieConstants.CELL_ADDR_PRE_FIX + (lastRow + 1);
    sheetConfig.setFormBodyRange(tempStr);
    sheetConfig.setBodyCellRange(new CellRange(tempStr));
    sheetConfig.setFormBodyType(org.tiefaces.common.TieConstants.FORM_TYPE_FREE);
    sheetConfig.setCellFormAttributes(new HashMap<String, List<CellFormAttributes>>());

    // check it's a hidden sheet
    int sheetIndex = parent.getWb().getSheetIndex(sheet);
    if (parent.getWb().isSheetHidden(sheetIndex) || parent.getWb().isSheetVeryHidden(sheetIndex)) {
        sheetConfig.setHidden(true);
    }

    return sheetConfig;

}

From source file:org.tiefaces.components.websheet.configuration.ConfigurationHandler.java

License:MIT License

/**
 * build top level configuration map from command list. User can either put
 * tie:form command in the comments (which will transfer to sheetConfig), Or
 * just ignore it, then use whole sheet as one form.
 *
 * @param sheet/*from w  w w.  ja  va  2  s.  com*/
 *            sheet.
 * @param sheetConfigMap
 *            sheetConfigMap.
 * @param commandList
 *            command list.
 * @param formList
 *            form list.
 * @param sheetRightCol
 *            the sheet right col
 */
private void buildSheetConfigMapFromFormCommand(final Sheet sheet,
        final Map<String, SheetConfiguration> sheetConfigMap, final List<ConfigCommand> commandList,
        final List<String> formList, final int sheetRightCol) {
    boolean foundForm = false;
    int minRowNum = sheet.getLastRowNum();
    int maxRowNum = sheet.getFirstRowNum();
    for (Command command : commandList) {
        // check whether is form command
        if (command.getCommandTypeName().equalsIgnoreCase(TieConstants.COMMAND_FORM)) {
            foundForm = true;
            FormCommand fcommand = (FormCommand) command;
            sheetConfigMap.put(fcommand.getName(),
                    getSheetConfigurationFromConfigCommand(sheet, fcommand, sheetRightCol));
            formList.add(fcommand.getName());
            if (fcommand.getTopRow() < minRowNum) {
                minRowNum = fcommand.getTopRow();
            }
            if (fcommand.getLastRow() > maxRowNum) {
                maxRowNum = fcommand.getLastRow();
            }
        }
    }
    // if no form found, then use the whole sheet as form
    if (!foundForm) {
        WebSheetUtility.clearHiddenColumns(sheet);
        String formName = sheet.getSheetName();
        SheetConfiguration sheetConfig = getSheetConfiguration(sheet, formName, sheetRightCol);
        FormCommand fcommand = buildFormCommandFromSheetConfig(sheetConfig, sheet);
        commandList.add(fcommand);
        sheetConfig.setFormCommand(fcommand);
        sheetConfigMap.put(formName, sheetConfig);
        formList.add(formName);
        minRowNum = sheet.getFirstRowNum();
        maxRowNum = sheet.getLastRowNum();
    }

    // if skip config then return.
    if (parent.isSkipConfiguration()) {
        return;
    }
    SaveAttrsUtility.setSaveAttrsForSheet(sheet, minRowNum, maxRowNum,
            parent.getCellAttributesMap().getTemplateCommentMap().get(TieConstants.SAVE_COMMENT_KEY_IN_MAP));
}

From source file:plugins.excel.client.util.ExcelReader.java

License:Microsoft Reference Source License

private HashMap<String, Integer> getColumnTypes(Sheet sheet, ArrayList<String> columnNames,
        boolean columnNamesInFirstLine) {
    Cell c = null;// w  ww.j  ava  2s  . c om
    int type = Types.NULL;
    boolean stopFor = false;
    HashMap<String, Integer> types = new HashMap<String, Integer>();

    for (int i = 0; i < columnNames.size(); i++) {
        type = Types.NULL;
        stopFor = false;
        for (int j = sheet.getFirstRowNum() + (columnNamesInFirstLine ? 1 : 0); j <= sheet
                .getLastRowNum(); j++) {
            c = sheet.getRow(j).getCell(i);
            if (c != null) {
                switch (c.getCellType()) {
                case (Cell.CELL_TYPE_STRING):
                case (Cell.CELL_TYPE_FORMULA):
                    type = Types.VARCHAR;
                    stopFor = true;
                    break;
                case (Cell.CELL_TYPE_NUMERIC):
                    if (DateUtil.isCellDateFormatted(c)) {
                        if (type != Types.VARCHAR && type != Types.DOUBLE) {
                            type = Types.DATE;
                        }
                    } else {
                        if (type != Types.VARCHAR) {
                            type = Types.DOUBLE;
                        }
                    }
                    break;
                case (Cell.CELL_TYPE_ERROR):
                    if (type == Types.NULL || type == Types.BOOLEAN) {
                        type = Types.INTEGER;
                    }
                    break;
                case (Cell.CELL_TYPE_BOOLEAN):
                    if (type == Types.NULL) {
                        type = Types.BOOLEAN;
                    }
                    break;
                }
            }

            if (stopFor) {
                break;
            }
        }

        types.put(columnNames.get(i), type);
    }
    return types;
}