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


   
  private Region convertToRegion() {
   
    return new Region(_firstRow, (short)_firstColumn, _lastRow, (short)_lastColumn);
  }
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 testCloneSheetBasic(){
    try{
      HSSFWorkbook b = new HSSFWorkbook();
      HSSFSheet s = b.createSheet("Test");
      s.addMergedRegion(new Region((short)0,(short)0,(short)1,(short)1));
      HSSFSheet clonedSheet = b.cloneSheet(0);
     
      assertEquals("One merged area", 1, clonedSheet.getNumMergedRegions());

    }
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

    row = sheet.createRow(1);
    cell = row.createCell((short)1);
    cell.setCellValue("second row, second cell");

    Region region = new Region(1, (short)0, 1, (short)1);  
    sheet.addMergedRegion(region);

    sheet.shiftRows(1, 1, 1);

    region = sheet.getMergedRegionAt(0);
    assertEquals("Merged region not moved over to row 2", 2, region.getRowFrom());

  }
View Full Code Here

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

    //create a region over the 2nd row and auto size the first column
    sheet.addMergedRegion(new Region(1,(short)0,1,(short)1));
    sheet.autoSizeColumn((short)0);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    wb.write(out);
    out.close();
View Full Code Here

                                  + (( double ) cellnum / 10000)));
                c = r.createCell(( short ) (cellnum + 1));
                c.setCellValue(new HSSFRichTextString("TEST"));
            }
        }
        s.addMergedRegion(new Region(( short ) 0, ( short ) 0, ( short ) 10,
                                     ( short ) 10));
        s.addMergedRegion(new Region(( short ) 30, ( short ) 5, ( short ) 40,
                                     ( short ) 15));
        wb.write(out);
        out.close();
        sanityChecker.checkHSSFWorkbook(wb);
        in = new FileInputStream(file);
        wb = new HSSFWorkbook(new POIFSFileSystem(in));
        s  = wb.getSheetAt(0);
        Region r1 = s.getMergedRegionAt(0);
        Region r2 = s.getMergedRegionAt(1);

        in.close();

        // System.out.println(file.length());
        // assertEquals("FILE LENGTH == 87552",file.length(), 87552);
        // System.out.println(s.getLastRowNum());
        assertEquals("REGION1 = 0,0,10,10", 0,
                     new Region(( short ) 0, ( short ) 0, ( short ) 10,
                                ( short ) 10).compareTo(r1));
        assertEquals("REGION2 == 30,5,40,15", 0,
                     new Region(( short ) 30, ( short ) 5, ( short ) 40,
                                ( short ) 15).compareTo(r2));
    }
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.