Package org.apache.poi.ss.util

Examples of org.apache.poi.ss.util.AreaReference


  protected final String formatReferenceAsString() {
    CellReference topLeft = new CellReference(getFirstRow(),getFirstColumn(),!isFirstRowRelative(),!isFirstColRelative());
    CellReference botRight = new CellReference(getLastRow(),getLastColumn(),!isLastRowRelative(),!isLastColRelative());

    if(AreaReference.isWholeColumnReference(topLeft, botRight)) {
      return (new AreaReference(topLeft, botRight)).formatAsString();
    }
    return topLeft.formatAsString() + ":" + botRight.formatAsString();
  }
View Full Code Here


       assertEquals("Abc,1", sheet.getSheetName());
      
       Name name = wb.getName("Intekon.ProdCodes");
       assertEquals("'Abc,1'!$A$1:$A$2", name.getRefersToFormula());
      
       AreaReference ref = new AreaReference(name.getRefersToFormula());
       assertEquals(0, ref.getFirstCell().getRow());
       assertEquals(0, ref.getFirstCell().getCol());
       assertEquals(1, ref.getLastCell().getRow());
       assertEquals(0, ref.getLastCell().getCol());
    }
View Full Code Here

     * @param templateSheet - template sheet
     * @param resultSheet   - result sheet
     */
    protected void writeHorizontalBand(BandData band, HSSFSheet templateSheet, HSSFSheet resultSheet) {
        String rangeName = band.getName();
        AreaReference templateRange = getAreaForRange(templateWorkbook, rangeName);
        if (templateRange == null) {
            throw wrapWithReportingException(String.format("No such named range in xls file: %s", rangeName));
        }
        CellReference[] crefs = templateRange.getAllReferencedCells();

        CellReference topLeft, bottomRight;
        AreaReference resultRange;

        int rowsAddedByHorizontalBandBackup = rowsAddedByHorizontalBand;
        int rownumBackup = rownum;

        if (crefs != null) {
            addRangeBounds(band, crefs);

            ArrayList<HSSFRow> resultRows = new ArrayList<HSSFRow>();

            int currentRowNum = -1;
            int currentRowCount = -1;
            int currentColumnCount = 0;
            int offset = 0;

            topLeft = new CellReference(rownum + rowsAddedByHorizontalBand, 0);
            // no child bands - merge regions now
            if (band.getChildrenList().isEmpty()) {
                copyMergeRegions(resultSheet, rangeName, rownum + rowsAddedByHorizontalBand,
                        getCellFromReference(crefs[0], templateSheet).getColumnIndex());
            }

            for (CellReference cellRef : crefs) {
                HSSFCell templateCell = getCellFromReference(cellRef, templateSheet);
                HSSFRow resultRow;
                if (templateCell.getRowIndex() != currentRowNum) { //create new row
                    resultRow = resultSheet.createRow(rownum + rowsAddedByHorizontalBand);
                    copyPageBreaks(templateSheet, resultSheet, templateCell.getRowIndex(), resultRow.getRowNum());
                    rowsAddedByHorizontalBand += 1;

                    //todo move to options
                    if (templateCell.getCellStyle().getParentStyle() != null
                            && templateCell.getCellStyle().getParentStyle().getUserStyleName() != null
                            && templateCell.getCellStyle().getParentStyle().getUserStyleName().equals(DYNAMIC_HEIGHT_STYLE)
                            ) {
                        //resultRow.setHeight(templateCell.getRow().getHeight());
                    } else {
                        resultRow.setHeight(templateCell.getRow().getHeight());
                    }
                    resultRows.add(resultRow);

                    currentRowNum = templateCell.getRowIndex();
                    currentRowCount++;
                    currentColumnCount = 0;
                    offset = templateCell.getColumnIndex();
                } else {                                          // or write cell to current row
                    resultRow = resultRows.get(currentRowCount);
                    currentColumnCount++;
                }

                copyCellFromTemplate(templateCell, resultRow, offset + currentColumnCount, band);
            }

            bottomRight = new CellReference(rownum + rowsAddedByHorizontalBand - 1, offset + currentColumnCount);
            resultRange = new AreaReference(topLeft, bottomRight);

            areaDependencyManager.addDependency(new Area(band.getName(), Area.AreaAlign.HORIZONTAL, templateRange),
                    new Area(band.getName(), Area.AreaAlign.HORIZONTAL, resultRange));
            bandsToResultRanges.put(band, new Range(resultSheet.getSheetName(),
                    resultRange.getFirstCell().getCol() + 1, resultRange.getFirstCell().getRow() + 1,
                    resultRange.getLastCell().getCol() + 1, resultRange.getLastCell().getRow() + 1
            ));
        }

        for (BandData child : band.getChildrenList()) {
            writeBand(child);
View Full Code Here

                bottomRight = new CellReference(resultCell);
            }

            colnum += crefs[crefs.length - 1].getCol() - firstColumn + 1;

            AreaReference templateRange = getAreaForRange(templateWorkbook, rangeName);
            AreaReference resultRange = new AreaReference(topLeft, bottomRight);
            areaDependencyManager.addDependency(new Area(band.getName(), Area.AreaAlign.VERTICAL, templateRange),
                    new Area(band.getName(), Area.AreaAlign.VERTICAL, resultRange));
            bandsToResultRanges.put(band, new Range(resultSheet.getSheetName(),
                    resultRange.getFirstCell().getCol() + 1, resultRange.getFirstCell().getRow() + 1,
                    resultRange.getLastCell().getCol() + 1, resultRange.getLastCell().getRow() + 1
            ));
        }

        //for first level vertical bands we should increase rownum by number of rows added by vertical band
        //nested vertical bands do not add rows, they use parent space
View Full Code Here

            String refersToFormula = aNamedRange.getRefersToFormula();
            if (!AreaReference.isContiguous(refersToFormula)) {
                continue;
            }

            AreaReference aref = new AreaReference(refersToFormula);
            Integer rangeFirstRow = aref.getFirstCell().getRow();
            Integer rangeFirstColumn = (int) aref.getFirstCell().getCol();
            Integer rangeLastRow = aref.getLastCell().getRow();
            Integer rangeLastColumn = (int) aref.getLastCell().getCol();

            for (int j = 0; j < currentSheet.getNumMergedRegions(); j++) {
                CellRangeAddress mergedRegion = currentSheet.getMergedRegion(j);
                if (mergedRegion != null) {
                    Integer regionFirstRow = mergedRegion.getFirstRow();
View Full Code Here

                                    int firstTargetRangeRow, int firstTargetRangeColumn) {
        int rangeNameIdx = templateWorkbook.getNameIndex(rangeName);
        if (rangeNameIdx == -1) return;

        HSSFName aNamedRange = templateWorkbook.getNameAt(rangeNameIdx);
        AreaReference aref = new AreaReference(aNamedRange.getRefersToFormula());
        int column = aref.getFirstCell().getCol();
        int row = aref.getFirstCell().getRow();

        List<SheetRange> regionsList = mergeRegionsForRangeNames.get(rangeName);
        if (regionsList != null)
            for (SheetRange sheetRange : regionsList) {
                if (resultSheet.getSheetName().equals(sheetRange.getSheetName())) {
View Full Code Here

    protected void updateFormulas(Area templateArea, Area dependentResultArea) {
        HSSFSheet templateSheet = getTemplateSheetForRangeName(templateWorkbook, templateArea.getName());
        HSSFSheet resultSheet = templateToResultSheetsMapping.get(templateSheet);

        AreaReference area = dependentResultArea.toAreaReference();
        for (CellReference cell : area.getAllReferencedCells()) {
            HSSFCell resultCell = getCellFromReference(cell, resultSheet);

            if (resultCell.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
                Ptg[] ptgs = HSSFFormulaParser.parse(resultCell.getCellFormula(), resultWorkbook);
View Full Code Here

    public void setAlign(AreaAlign align) {
        this.align = align;
    }

    public AreaReference toAreaReference() {
        return new AreaReference(topLeft.toCellReference(), bottomRight.toCellReference());
    }
View Full Code Here

                regionFirstRow <= rangeFirstRow && regionFirstRow <= rangeLastRow &&
                regionLastRow >= rangeFirstRow && regionLastRow >= rangeLastRow;
    }

    public static CellReference[] getRangeContent(HSSFWorkbook workbook, String rangeName) {
        AreaReference areaForRange = getAreaForRange(workbook, rangeName);
        if (areaForRange == null) {
            return null;
        }

        return areaForRange.getAllReferencedCells();
    }
View Full Code Here

    public static AreaReference getAreaForRange(HSSFWorkbook workbook, String rangeName) {
        int rangeNameIdx = workbook.getNameIndex(rangeName);
        if (rangeNameIdx == -1) return null;

        HSSFName aNamedRange = workbook.getNameAt(rangeNameIdx);
        return new AreaReference(aNamedRange.getReference());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.util.AreaReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.