Package org.apache.poi.ss.util

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


      sheetName = (String)stack.getValue("sheetName");
    if(sheetName != null) wb.setSheetName(wb.getSheetIndex(sheet), sheetName);
   
    Map<ExcelBlock, List<CellRangeAddress>> mergedRegions = new HashMap<ExcelBlock, List<CellRangeAddress>>();
    for(int i=0; i< sheet.getNumMergedRegions(); i++){
      CellRangeAddress cra = sheet.getMergedRegion(i);
      logger.debug("Merged Region:[{}-{}]",
          ExcelUtil.getCellIndex(cra.getFirstRow(), cra.getFirstColumn()),
          ExcelUtil.getCellIndex(cra.getLastRow(), cra.getLastColumn()));
      for(ExcelBlock blockDefinition: sheetDefinition.getSortedExcelBlocks()){
        if(cra.getFirstRow() >= blockDefinition.getStartRow() &&
            cra.getFirstColumn() >= blockDefinition.getStartCol() &&
            cra.getLastRow() <= blockDefinition.getEndRow() &&
            cra.getLastColumn() <= blockDefinition.getEndCol()){
          List<CellRangeAddress> cras = mergedRegions.get(blockDefinition);
          if(cras == null){
            cras = new ArrayList<CellRangeAddress>();
            mergedRegions.put(blockDefinition, cras);           
          }
View Full Code Here


        stack.removeContext("lineNum");
             
        //if no data, just remove the dummy data   
        //[2013-2-26]it seems that we also need to remove all merged regions for shift   
        for(int i=sheet.getNumMergedRegions()-1; i>=0; i--){
          CellRangeAddress cra = sheet.getMergedRegion(i);       
          if(cra.getFirstRow() >= blockDefinition.getStartRow() &&
              cra.getFirstColumn() >= blockDefinition.getStartCol() &&
              cra.getLastRow() <= blockDefinition.getEndRow() &&
              cra.getLastColumn() <= blockDefinition.getEndCol()){
            sheet.removeMergedRegion(i);
            logger.debug("Removed Merged Region:[{}-{}]",
                ExcelUtil.getCellIndex(cra.getFirstRow(), cra.getFirstColumn()),
                ExcelUtil.getCellIndex(cra.getLastRow(), cra.getLastColumn()));
          }
        }
        //[2013-2-22]if with data, still need to remove dummy one, otherwise xlsx will have error if there are formulas in block.
        for(int i = blockDefinition.getEndRow(); i>= blockDefinition.getStartRow(); i--)
          sheet.removeRow(sheet.getRow(i));     
View Full Code Here

    if (rowSpan <= 1 && columnSpan <= 1)
    {
      return;
    }

    sheet.addMergedRegion(new CellRangeAddress(row, (row + rowSpan - 1), col, (col + columnSpan - 1)));
    final int rectX = rectangle.getX1();
    final int rectY = rectangle.getY1();

    for (int spannedRow = 0; spannedRow < rowSpan; spannedRow += 1)
    {
View Full Code Here

    }

    int row = rectangle.getY1();
    int col = rectangle.getX1();

    sheet.addMergedRegion(new CellRangeAddress(row, (row + rowSpan - 1), col, (col + columnSpan - 1)));

    for (int spannedRow = 0; spannedRow < rowSpan; spannedRow += 1)
    {
      for (int spannedCol = 0; spannedCol < columnSpan; spannedCol += 1)
      {
View Full Code Here

                if ( cell == null ) {
                    continue;
                }
                double num = 0;

                CellRangeAddress merged = getRangeIfMerged( cell,
                                                            mergedRanges );

                int mergedColStart = DataListener.NON_MERGED;
                if ( merged != null ) {
                    cell = sheet.getRow(merged.getFirstRow()).getCell(merged.getFirstColumn());
                    mergedColStart = cell.getColumnIndex();
                }

                switch ( cell.getCellType() ) {
                    case Cell.CELL_TYPE_FORMULA:
View Full Code Here

    }

    CellRangeAddress getRangeIfMerged( Cell cell,
                                       CellRangeAddress[] mergedRanges ) {
        for ( int i = 0; i < mergedRanges.length; i++ ) {
            CellRangeAddress r = mergedRanges[ i ];
            if ( r.isInRange( cell.getRowIndex(), cell.getColumnIndex() ) ) {
                return r;
            }
        }
        return null;
    }
View Full Code Here

        sheet.autoSizeColumn((short)0);
        assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) >= minWithRow1And2);
        assertTrue("Column autosized with only one row: wrong width", sheet.getColumnWidth(0) <= maxWithRow1And2);

        //create a region over the 2nd row and auto size the first column
        sheet.addMergedRegion(new CellRangeAddress(1,1,0,1));
        sheet.autoSizeColumn((short)0);
        HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb);

        // check that the autoSized column width has ignored the 2nd row
        // because it is included in a merged region (Excel like behavior)
View Full Code Here

        LbsDataSubRecord lbs = (LbsDataSubRecord)sr;
        assertEquals(4, lbs.getNumberOfItems());

        assertTrue(lbs.getFormula() instanceof AreaPtg);
        AreaPtg ptg = (AreaPtg)lbs.getFormula();
        CellRangeAddress range = new CellRangeAddress(
                ptg.getFirstRow(), ptg.getLastRow(), ptg.getFirstColumn(), ptg.getLastColumn());
        assertEquals("H10:H13", range.formatAsString());

        // check that it re-serializes to the same data
        byte[] ser = record.serialize();
        TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, ser);
    }
View Full Code Here

     */
    protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) {
        List<CellRangeAddress> shiftedRegions = new ArrayList<CellRangeAddress>();
        //move merged regions completely if they fall within the new region boundaries when they are shifted
        for (int i = 0; i < getNumMergedRegions(); i++) {
             CellRangeAddress merged = getMergedRegion(i);

             boolean inStart= (merged.getFirstRow() >= startRow || merged.getLastRow() >= startRow);
             boolean inEnd  = (merged.getFirstRow() <= endRow   || merged.getLastRow() <= endRow);

             //don't check if it's not within the shifted area
             if (!inStart || !inEnd) {
                continue;
             }

             //only shift if the region outside the shifted rows is not merged too
             if (!containsCell(merged, startRow-1, 0) && !containsCell(merged, endRow+1, 0)){
                 merged.setFirstRow(merged.getFirstRow()+n);
                 merged.setLastRow(merged.getLastRow()+n);
                 //have to remove/add it back
                 shiftedRegions.add(merged);
                 removeMergedRegion(i);
                 i = i -1; // we have to back up now since we removed one
             }
        }

        //read so it doesn't get shifted again
        Iterator<CellRangeAddress> iterator = shiftedRegions.iterator();
        while (iterator.hasNext()) {
            CellRangeAddress region = iterator.next();

            this.addMergedRegion(region);
        }
    }
View Full Code Here

                continue;
            }

            int colspan = 1;
            for (int i = 0 ; i < getNumMergedRegions(); i++) {
                CellRangeAddress region = getMergedRegion(i);
                if (containsCell(region, row.getRowNum(), column)) {
                    if (!useMergedCells) {
                        // If we're not using merged cells, skip this one and move on to the next.
                        continue rows;
                    }
                    cell = row.getCell(region.getFirstColumn());
                    colspan = 1 + region.getLastColumn() - region.getFirstColumn();
                }
            }

            HSSFCellStyle style = cell.getCellStyle();
            int cellType = cell.getCellType();
View Full Code Here

TOP

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

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.