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

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

Introduction

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

Prototype

short getFirstCellNum();

Source Link

Document

Get the number of the first cell contained in this row.

Usage

From source file:org.lisapark.octopus.util.json.JsonUtils.java

License:Open Source License

private String jsonFromRowAsTreeNode(Row row, String stringCells, List<String> stack, int increment) {
    String stringRow;/*from   ww w .  j a  v  a2 s . c  om*/
    Cell cell = row.getCell(row.getFirstCellNum());
    if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getStringCellValue().length() > 0) {
        stringRow = jsonApplyIndentationAsString(stringCells, row, stack, increment);
    } else {
        stringRow = "{" + SPREAD_SHEET_ROW + " : " + stringCells + "}";
    }
    return stringRow;
}

From source file:org.lisapark.octopus.util.json.JsonUtils.java

License:Open Source License

/**
 * /*from  w  ww  . j  av  a 2  s .  c  o  m*/
 * @param jsonCells
 * @param row
 * @param stack
 * @param increment
 * @return
 * @throws JSONException 
 */
private JSONObject applyIndentation(JSONArray jsonCells, Row row, List<String> stack, int increment)
        throws JSONException {
    JSONObject jsonRow = new JSONObject();

    Cell cell = row.getCell(row.getFirstCellNum());
    String nodeName = cell.getStringCellValue() + "";
    int indent = cell.getCellStyle().getIndention();
    int absIndent = indent / increment;

    if (indent == 0) {
        jsonRow = jsonRow.put(nodeName + "", jsonCells);
    } else if (absIndent > (stack.size() - 1)) {
        jsonRow = buildNestedJsonObject(jsonRow, nodeName, jsonCells, stack);
    } else {
        // remove items from the top of the stack
        for (int i = stack.size(); i > absIndent; i--) {
            stack.remove(i - 1);
        }
        jsonRow = buildNestedJsonObject(jsonRow, nodeName, jsonCells, stack);
    }

    return jsonRow;
}

From source file:org.lisapark.octopus.util.json.JsonUtils.java

License:Open Source License

/**
 * //  w  ww .j  a  v a  2  s.  c  om
 * @param jsonCells
 * @param row
 * @param stack
 * @param increment
 * @return 
 */
private String jsonApplyIndentationAsString(String stringCells, Row row, List<String> stack, int increment) {
    StringBuilder stringBuilder = new StringBuilder();

    Cell cell = row.getCell(row.getFirstCellNum());
    String nodeName = cell.getStringCellValue();

    if (nodeName.isEmpty()) {
        nodeName = DEFAULT_NODE_NAME;
    }

    int indent = cell.getCellStyle().getIndention();
    int absIndent = indent / increment;

    if (absIndent > 0 && absIndent <= (stack.size() - 1)) {
        // remove items from the top of the stack
        for (int i = stack.size() - 1; i >= absIndent; --i) {
            stack.remove(i);
        }
        stack.add(nodeName);
        stringBuilder = buildNestedJsonString(stringCells, stack);
    } else if (absIndent > (stack.size() - 1)) {
        stack.add(nodeName);
        stringBuilder = buildNestedJsonString(stringCells, stack);
    } else if (absIndent == 0) {
        stringBuilder = stringBuilder.append("{" + "\"").append(nodeName.replace('.', '_')).append("\"" + " : ")
                .append(stringCells).append("}");
        stack.removeAll(stack);
        stack.add(nodeName);
    }

    return stringBuilder.toString();
}

From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java

License:Open Source License

private static List<String> getDateList(Sheet sheet, int start, int rangeLen) {
    List<String> dateList = Lists.newArrayList();

    if (sheet.getPaneInformation() != null && sheet.getPaneInformation().isFreezePane()) {
        int splitRowNumber = sheet.getPaneInformation().getHorizontalSplitPosition();
        Row row = sheet.getRow(splitRowNumber - WAREHOUSE_DATE_ROW_SHIFT);
        int currCellNumber = row.getFirstCellNum() + start + 1;

        while (currCellNumber <= row.getPhysicalNumberOfCells()) {
            dateList.add(row.getCell(currCellNumber).getStringCellValue());
            currCellNumber += rangeLen;//w  w w  . ja va  2s  .  c o m
        }
    } else {
        dateList = null;
    }
    return dateList;
}

From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java

License:Open Source License

private static String tagNodesAsString(Row row, int dataRangeStart, int dataRangeLen) throws JSONException {
    StringBuilder nodeStringBuilder = new StringBuilder();
    StringBuilder rowStringBuilder = new StringBuilder();

    int start;//from  ww w.  j a  va  2  s  . c  o  m
    int end;

    // Define start and end points of cell range to be converted
    if (dataRangeStart == -1) {
        start = row.getFirstCellNum();
    } else {
        start = row.getFirstCellNum() + dataRangeStart;
    }
    if (dataRangeLen == 0) {
        end = row.getPhysicalNumberOfCells();
    } else {
        end = start + dataRangeLen;
    }
    int i = 0;
    int j = 0;
    // Itarate over cell range and build xml nodes
    for (Iterator<Cell> cellsIT = row.cellIterator(); cellsIT.hasNext();) {
        if (i >= end) {
            break;
        }
        Cell cell = cellsIT.next();
        // Skip cells that are out of range
        if (i > 0 && i < start) {
            i++;
            continue;
        }
        // Build all nodes from Spreadsheet row with specified cell range
        rowStringBuilder = rowStringBuilder.append(buidNodeAsString(cell, i, j));
        i++;
        j++;
    }
    return nodeStringBuilder.append(rowStringBuilder.toString()).toString();
}

From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java

License:Open Source License

/**
 * /*  www. j  a  v a 2s  .  c o m*/
 * @param jsonCells
 * @param row
 * @param stack
 * @param increment
 * @return 
 */
private static String xmlFromRowAsTreeAttributes(String tagAttributes, Row row, List<String> stack,
        int increment) {
    String tagString = "";

    Cell cell = row.getCell(row.getFirstCellNum());

    int indent = cell.getCellStyle().getIndention();
    int absIndent = indent / increment;

    int diff = stack.size() - absIndent;

    if (diff == 0) {
        tagString = leftTagWithAttributes(treeNodeNames.get(absIndent), tagAttributes);
        stack.add(treeNodeNames.get(absIndent));
    } else if (diff > 0) {
        while (diff > 0) {
            tagString = tagString + rightTag(stack.get(stack.size() - 1));
            stack.remove(stack.size() - 1);
            diff--;
        }
        tagString = tagString + leftTagWithAttributes(treeNodeNames.get(absIndent), tagAttributes);
        stack.add(treeNodeNames.get(absIndent));
    }
    return tagString;
}

From source file:org.lisapark.octopus.util.xml.XmlConverterUtils.java

License:Open Source License

/**
 * /*from w ww. j ava2s .  c  o  m*/
 * @param tagNodes
 * @param row
 * @param stack
 * @param increment
 * @return 
 */
private static String xmlFromRowAsTreeNodes(String tagNodes, Row row, List<String> stack, int increment) {
    String tagString = "";

    Cell cell = row.getCell(row.getFirstCellNum());

    int indent = cell.getCellStyle().getIndention();
    int absIndent = indent / increment;

    int diff = stack.size() - absIndent;

    if (diff == 0) {
        tagString = leftTagWithNodes(treeNodeNames.get(absIndent), tagNodes);
        stack.add(treeNodeNames.get(absIndent));
    } else if (diff > 0) {
        while (diff > 0) {
            tagString = tagString + rightTag(stack.get(stack.size() - 1));
            stack.remove(stack.size() - 1);
            diff--;
        }
        tagString = tagString + leftTagWithNodes(treeNodeNames.get(absIndent), tagNodes);
        stack.add(treeNodeNames.get(absIndent));
    }
    return tagString;
}

From source file:org.paxml.bean.excel.ReadExcelTag.java

License:Open Source License

private Iterator doBasic(Context context) throws Exception {

    return new Iterator() {
        private Iterator<Row> it;
        private int index;
        private Map<Integer, String> headers = new HashMap<Integer, String>();

        private void start() {

            boolean ok = false;
            try {

                Sheet s = getExcelSheet(false);

                it = s.iterator();//  w  w w . j  av a 2s .c  o  m
                // find the start row
                if (log.isDebugEnabled()) {
                    log.debug("Start reading from row " + Math.max(1, firstRow) + " of sheet: "
                            + s.getSheetName());
                }

                for (int i = 1; i < firstRow && it.hasNext(); i++) {
                    it.next();
                    index++;
                }

                ok = true;
            } finally {
                if (!ok) {
                    end();
                }
            }
        }

        private void end() {
            it = null;
            file.close();
        }

        @Override
        public boolean hasNext() {
            if (it == null) {
                start();
            }
            if (lastRow > 0 && index > lastRow - 1) {
                end();
                return false;
            }
            try {
                boolean has = it.hasNext();
                if (!has) {
                    end();
                }
                return has;
            } catch (Exception e) {
                end();
                throw new PaxmlRuntimeException(e);
            }
        }

        @Override
        public Object next() {
            try {
                Row row = it.next();
                Object r = readRow(row);
                index++;
                return r;
            } catch (Exception e) {
                end();
                throw new PaxmlRuntimeException(e);
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        private Map<Object, Object> readRow(Row row) {

            final int firstCell = Math.max(row.getFirstCellNum(), _firstColumn);
            final int lastCell = _lastColumn < 0 ? row.getLastCellNum() - 1
                    : Math.min(row.getLastCellNum() - 1, _lastColumn);

            if (log.isDebugEnabled()) {
                log.debug("Reading cells: " + new CellReference(index, firstCell).formatAsString() + ":"
                        + new CellReference(index, lastCell).formatAsString());
            }

            Map<Object, Object> result = new LinkedHashMap<Object, Object>();
            for (int i = firstCell; i <= lastCell; i++) {
                Cell cell = row.getCell(i);
                if (cell != null) {
                    Object value = file.getCellValue(cell);
                    // dual keys for the same value
                    result.put(i, value);
                    String key = headers.get(i);
                    if (key == null) {
                        key = new CellReference(-1, i).formatAsString();
                        headers.put(i, key);
                    }
                    result.put(key, value);
                }
            }
            return result;
        }

    };

}

From source file:org.projectforge.excel.ExportRow.java

License:Open Source License

public ExportRow(final ContentProvider contentProvider, final ExportSheet sheet, final Row poiRow,
        final int rowNum) {
    this.contentProvider = contentProvider;
    this.sheet = sheet;
    this.poiRow = poiRow;
    this.rowNum = rowNum;
    cellMap = new HashMap<Integer, ExportCell>();
    if (poiRow.getLastCellNum() > 0) {
        // poiRow does already exists.
        for (int i = poiRow.getFirstCellNum(); i < poiRow.getLastCellNum(); i++) {
            final Cell poiCell = poiRow.getCell(i);
            if (poiCell != null) {
                addPoiCell(i, poiCell);/*from  w ww  .  j  ava 2 s. com*/
            }
        }
    }
}

From source file:org.projectforge.export.ExportRow.java

License:Open Source License

public ExportRow(ContentProvider contentProvider, ExportSheet sheet, Row poiRow, int rowNum) {
    this.contentProvider = contentProvider;
    this.sheet = sheet;
    this.poiRow = poiRow;
    this.rowNum = rowNum;
    cellMap = new HashMap<Integer, ExportCell>();
    if (poiRow.getLastCellNum() > 0) {
        // poiRow does already exists.
        for (int i = poiRow.getFirstCellNum(); i < poiRow.getLastCellNum(); i++) {
            Cell poiCell = poiRow.getCell(i);
            if (poiCell != null) {
                addPoiCell(i, poiCell);/* w w w .j a  v  a2  s .  co  m*/
            }
        }
    }
}