Package org.apache.poi.hssf.util

Examples of org.apache.poi.hssf.util.Region


     * @return the merged region (simple eh?)
     */

    public Region getMergedRegionAt(int index)
    {
        return new Region(sheet.getMergedRegionAt(index));
    }
View Full Code Here


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

       boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
       boolean inEnd =  (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);

       //dont 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 (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
         merged.setRowFrom(merged.getRowFrom()+n);
         merged.setRowTo(merged.getRowTo()+n);
         //have to remove/add it back
         shiftedRegions.add(merged);
         this.removeMergedRegion(i);
         i = i -1; // we have to back up now since we removed one

       }

    }

    //readd so it doesn't get shifted again
    Iterator iterator = shiftedRegions.iterator();
    while (iterator.hasNext()) {
      Region region = (Region)iterator.next();

      this.addMergedRegion(region);
    }

  }
View Full Code Here

        groupValue = (String) table.getValueAt(j - currentRow,
            groupColumn);
        row = sheet.createRow((short) l);
        createCell(row, cellStyle.getGroupStyle(), (short) 0,
            groupValue);
        sheet.addMergedRegion(new Region((short) l, (short) 0,
            (short) l,
            (short) (columnCount - notVisibleColumnsSize - 1)));
        l++;

      }
View Full Code Here

            groupColumn);
        row = excelSheet.createRow((short) l);

        createCell(row, cellStyle.getGroupStyle(),
            (short) (startCell - addedColumn), groupValue);
        excelSheet.addMergedRegion(new Region((short) l, (short) 0,
            (short) l, (short) (columnCount + addedColumn
                - notVisibleColumnsSize - 1)));
        l++;

      }
View Full Code Here

    // g�r gjennom grupperingssummer og skriver inn formler
    for (ExcelGroupSum excelGroupSum : formulaCells) {
      excelGroupSum.setFormula();

      if (groupResultColumn != null) {
        excelSheet.addMergedRegion(new Region((short) (excelGroupSum
            .getFromRow() - 1), (short) (groupResultColumn
            .shortValue() + addedColumn), (short) (excelGroupSum
            .getToRow() - 1), (short) (groupResultColumn
            .shortValue() + addedColumn)));
      }
View Full Code Here

        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.SEA_GREEN.index, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_MEDIUM, null), (short) 0, "SALGSM�L");

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 0,
        (short) currentRow - 1, (short) 20));

    row = sheet.createRow((short) currentRow++);

    for (int i = 0; i <= 20; i++) {
      createCell(row, cellStyle.getStyle((short) 10,
          HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
          HSSFColor.GREY_25_PERCENT.index,
          HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_MEDIUM,
          HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_THIN,
          null), (short) i, "");
    }

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 2, "Salgsm�l "
        + reportSetting.getYear());

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 2,
        (short) currentRow - 1, (short) 4));

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 5, "Uke "
        + reportSetting.getWeekFrom());

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 5,
        (short) currentRow - 1, (short) 12));

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 13,
        "Akkumulert pr uke " + reportSetting.getWeekFrom());

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 13,
        (short) currentRow - 1, (short) 20));

    row = sheet.createRow((short) currentRow++);

    for (int i = 0; i <= 1; i++) {
      createCell(row, cellStyle.getStyle((short) 10,
          HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
          HSSFColor.GREY_25_PERCENT.index,
          HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_THIN,
          HSSFCellStyle.BORDER_MEDIUM, HSSFCellStyle.BORDER_THIN,
          null), (short) i, "");
    }

    for (int i = 2; i <= 4; i++) {
      createCell(row, cellStyle.getStyle((short) 10,
          HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
          HSSFColor.GREY_25_PERCENT.index, null,
          HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_THIN,
          HSSFCellStyle.BORDER_THIN, null), (short) i, "");
    }

    for (int i = 5; i <= 20; i++) {
      createCell(row, cellStyle.getStyle((short) 10,
          HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
          HSSFColor.GREY_25_PERCENT.index, null,
          HSSFCellStyle.BORDER_THIN, null, HSSFCellStyle.BORDER_THIN,
          null), (short) i, "");
    }

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, null,
        HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 20, "");

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 5, "pr uke");

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 5,
        (short) currentRow - 1, (short) 9));

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN,
        HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 10,
        "Endring fra i fjor(diff):");

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 10,
        (short) currentRow - 1, (short) 12));

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 13, "pr uke");

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 13,
        (short) currentRow - 1, (short) 17));

    createCell(row, cellStyle.getStyle((short) 10,
        HSSFFont.BOLDWEIGHT_BOLD, HSSFCellStyle.ALIGN_CENTER,
        HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN,
        HSSFCellStyle.BORDER_THIN, HSSFCellStyle.BORDER_MEDIUM,
        HSSFCellStyle.BORDER_THIN, null), (short) 18,
        "Endring fra i fjor(diff):");

    sheet.addMergedRegion(new Region((short) currentRow - 1, (short) 18,
        (short) currentRow - 1, (short) 20));

    row = sheet.createRow((short) currentRow++);

    createCell(row,
View Full Code Here

                           final ElementProcessor parent)
        throws IOException
    {
        super.initialize(attributes, parent);

        Region region = new Region(getStartRow(),
                                   (short)getStartCol(),
                                   getEndRow(),
                                   (short)getEndCol());

//        if (region.getRowFrom() == 0 &&
//            region.getColumnFrom() ==0)
//            getLogger().debug("got 0,0");

        getLogger().debug("region area is "+region.getArea());
        if(region.getArea() < MAX_AREA) {  //protect against stupid mega regions
                                       //of generally NOTHING and no real
                                       //puprose created by gnumeric
            getLogger().debug("region added");
            _style = getSheet().addStyleRegion(region
                                      ); //test
View Full Code Here

     * @return the merged region (simple eh?)
     */

    public Region getMergedRegionAt(int index)
    {
        return new Region(sheet.getMergedRegionAt(index));
    }
View Full Code Here

   */
  protected void shiftMerged(int startRow, int endRow, int n, boolean isRow) {
    List shiftedRegions = new ArrayList();
    //move merged regions completely if they fall within the new region boundaries when they are shifted
    for (int i = 0; i < this.getNumMergedRegions(); i++) {
       Region merged = this.getMergedRegionAt(i);
           
       boolean inStart = (merged.getRowFrom() >= startRow || merged.getRowTo() >= startRow);
       boolean inEnd =  (merged.getRowTo() <= endRow || merged.getRowFrom() <= endRow);
           
       //dont 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 (!merged.contains(startRow-1, (short)0) && !merged.contains(endRow+1, (short)0)){
         merged.setRowFrom(merged.getRowFrom()+n);         
         merged.setRowTo(merged.getRowTo()+n);
         //have to remove/add it back
         shiftedRegions.add(merged);
         this.removeMergedRegion(i);
         i = i -1; // we have to back up now since we removed one
         
       }
           
    }
   
    //readd so it doesn't get shifted again
    Iterator iterator = shiftedRegions.iterator();
    while (iterator.hasNext()) {
      Region region = (Region)iterator.next();
     
      this.addMergedRegion(region);
    }
   
  }
View Full Code Here

   *
   */   
  public void testRemoveMerged() {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    Region region = new Region(0, (short)0, 1, (short)1);    
    sheet.addMergedRegion(region);
    region = new Region(1, (short)0, 2, (short)1);
    sheet.addMergedRegion(region);
   
      sheet.removeMergedRegion(0);
     
      region = sheet.getMergedRegionAt(0);
      assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom());
     
      sheet.removeMergedRegion(0);
     
    assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions());
   
    //an, add, remove, get(0) would null pointer
    sheet.addMergedRegion(region);
    assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
    sheet.removeMergedRegion(0);
    assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions());
    //add it again!
    region.setRowTo(4);
     
    sheet.addMergedRegion(region);
    assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions());
   
    //should exist now!
    assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions());
    region = sheet.getMergedRegionAt(0);
    assertEquals("the merged row to doesnt match the one we put in ", 4, region.getRowTo());
     
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.util.Region

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.