Package org.apache.poi.ss.util

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


    /**
     * Initialize a new document link
     */
    public void newDocumentLink() {
        _range = new CellRangeAddress(0, 0, 0, 0);
        _guid = STD_MONIKER;
        _linkOpts = HLINK_LABEL | HLINK_PLACE;
        setLabel("");
        _moniker = FILE_MONIKER;
        setAddress("");
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

public final class TestCloneSheet extends TestCase {

  public void testCloneSheetBasic(){
    HSSFWorkbook b = new HSSFWorkbook();
    HSSFSheet s = b.createSheet("Test");
    s.addMergedRegion(new CellRangeAddress(0, 1, 0, 1));
    HSSFSheet clonedSheet = b.cloneSheet(0);
   
    assertEquals("One merged area", 1, clonedSheet.getNumMergedRegions());
  }
View Full Code Here

                                  + (( double ) cellnum / 10000)));
                c = r.createCell(cellnum + 1);
                c.setCellValue(new HSSFRichTextString("TEST"));
            }
        }
        s.addMergedRegion(new CellRangeAddress(0, 10, 0, 10));
        s.addMergedRegion(new CellRangeAddress(30, 40, 5, 15));
        sanityChecker.checkHSSFWorkbook(wb);
        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
       
        s  = wb.getSheetAt(0);
        CellRangeAddress r1 = s.getMergedRegion(0);
        CellRangeAddress r2 = s.getMergedRegion(1);

        confirmRegion(new CellRangeAddress(0, 10, 0, 10), r1);
        confirmRegion(new CellRangeAddress(30, 40,5, 15), r2);
    }
View Full Code Here

      rule1, rule2
    };

    short col = 1;
    CellRangeAddress [] regions = {
      new CellRangeAddress(0, 65535, col, col)
    };

    sheetCF.addConditionalFormatting(regions, cfRules);
    sheetCF.addConditionalFormatting(regions, cfRules);

    // Verification
    assertEquals(2, sheetCF.getNumConditionalFormattings());
    sheetCF.removeConditionalFormatting(1);
    assertEquals(1, sheetCF.getNumConditionalFormattings());
    HSSFConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
    assertNotNull(cf);

    regions = cf.getFormattingRanges();
    assertNotNull(regions);
    assertEquals(1, regions.length);
    CellRangeAddress r = regions[0];
    assertEquals(1, r.getFirstColumn());
    assertEquals(1, r.getLastColumn());
    assertEquals(0, r.getFirstRow());
    assertEquals(65535, r.getLastRow());

    assertEquals(2, cf.getNumberOfRules());

    rule1 = cf.getRule(0);
    assertEquals("7",rule1.getFormula1());
View Full Code Here

      rule1, rule2
    };

    short col = 1;
    CellRangeAddress [] regions = {
      new CellRangeAddress(0, 65535, col, col)
    };

    sheetCF.addConditionalFormatting(regions, cfRules);
     
    try {
View Full Code Here

    HSSFPatternFormatting patternFmt = rule1.createPatternFormatting();
    patternFmt.setFillBackgroundColor(HSSFColor.YELLOW.index);
    HSSFConditionalFormattingRule [] cfRules = { rule1, };

    CellRangeAddress [] regions = {
      new CellRangeAddress(2, 4, 0, 0), // A3:A5
    };
    sheetCF.addConditionalFormatting(regions, cfRules);

    // This row-shift should destroy the CF region
    sheet.shiftRows(10, 20, -9);
View Full Code Here

   */
  public void testMovingMergedRegion() {
    List<Record> records = new ArrayList<Record>();

    CellRangeAddress[] cras = {
      new CellRangeAddress(0, 1, 0, 2),
    };
    MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
    records.add(BOFRecord.createSheetBOF());
    records.add(new DimensionsRecord());
    records.add(new RowRecord(0));
View Full Code Here

        Workbook wb = getTestDataProvider().createWorkbook();
        Sheet sheet = wb.createSheet();
        assertEquals(0, sheet.getNumMergedRegions());
        SpreadsheetVersion ssVersion = getTestDataProvider().getSpreadsheetVersion();

        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1);
        sheet.addMergedRegion(region);
        assertEquals(1, sheet.getNumMergedRegions());

        try {
            region = new CellRangeAddress(-1, -1, -1, -1);
            sheet.addMergedRegion(region);
            fail("Expected exception");
        } catch (IllegalArgumentException e){
            ;
        }
        try {
            region = new CellRangeAddress(0, 0, 0, ssVersion.getLastColumnIndex() + 1);
            sheet.addMergedRegion(region);
            fail("Expected exception");
        } catch (IllegalArgumentException e){
            ;
        }
        try {
            region = new CellRangeAddress(0, ssVersion.getLastRowIndex() + 1, 0, 1);
            sheet.addMergedRegion(region);
            fail("Expected exception");
        } catch (IllegalArgumentException e){
            ;
        }
View Full Code Here

     *
     */
    public void testRemoveMerged() {
        Workbook wb = getTestDataProvider().createWorkbook();
        Sheet sheet = wb.createSheet();
        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 1);
        sheet.addMergedRegion(region);
        region = new CellRangeAddress(1, 2, 0, 1);
        sheet.addMergedRegion(region);

        sheet.removeMergedRegion(0);

        region = sheet.getMergedRegion(0);
        assertEquals("Left over region should be starting at row 1", 1, region.getFirstRow());

        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.setLastRow(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.getMergedRegion(0);
        assertEquals("the merged row to doesnt match the one we put in ", 4, region.getLastRow());
    }
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.