Package org.apache.poi.hssf.util

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


   */
  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


        HSSFRow row = sheet.createRow((short) 1);
        HSSFCell cell = row.createCell((short) 1);
        cell.setCellValue("This is a test of merging");

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

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
        fileOut.close();
View Full Code Here

        HSSFRow row = sheet.createRow((short) 1);
        HSSFCell cell = row.createCell((short) 1);
        cell.setCellValue("This is a test of merging");

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

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
        wb.write(fileOut);
        fileOut.close();
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

                           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

     * @deprecated (Aug-2008) use {@link HSSFSheet#getMergedRegion(int)}
     */
    public Region getMergedRegionAt(int index) {
        CellRangeAddress cra = getMergedRegion(index);

        return new Region(cra.getFirstRow(), (short)cra.getFirstColumn(),
                cra.getLastRow(), (short)cra.getLastColumn());
    }
View Full Code Here

    public void test22720() throws Exception {
       HSSFWorkbook workBook = new HSSFWorkbook();
       workBook.createSheet("TEST");      
       HSSFSheet template = workBook.getSheetAt(0);
      
       template.addMergedRegion(new Region(0, (short)0, 1, (short)2));
       template.addMergedRegion(new Region(1, (short)0, 2, (short)2));
      
       HSSFSheet clone = workBook.cloneSheet(0);
       int originalMerged = template.getNumMergedRegions();
       assertEquals("2 merged regions", 2, originalMerged);
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

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.