All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jett.formula.CellRefRange Maven / Gradle / Ivy

Go to download

JETT is a Java API that reads an Excel spreadsheet as a template, takes your data, and creates a new Excel spreadsheet that contains your data, formatted as in the template. It works with .xls and .xlsx template spreadsheets.

The newest version!
package net.sf.jett.formula;

import org.apache.poi.ss.usermodel.Cell;

/**
 * A CellRefRange is a CellRef, representing a range.
 * The inherited attributes represent the upper-left corner of a block of
 * cells.  An additional internal CellRef represents the bottom-
 * right corner of the block of cells.
 *
 * @author Randy Gettman
 */
public class CellRefRange extends CellRef
{
    private CellRef myRangeEndCellRef = null;

    public CellRefRange(String cellRef)
    {
        super(cellRef);
    }

    public CellRefRange(int pRow, int pCol)
    {
        super(pRow, pCol);
    }

    public CellRefRange(int pRow, short pCol)
    {
        super(pRow, pCol);
    }

    public CellRefRange(Cell cell)
    {
        super(cell);
    }

    public CellRefRange(int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
    {
        super(pRow, pCol, pAbsRow, pAbsCol);
    }

    public CellRefRange(String pSheetName, int pRow, int pCol, boolean pAbsRow, boolean pAbsCol)
    {
        super(pSheetName, pRow, pCol, pAbsRow, pAbsCol);
    }

    /**
     * Sets the end of the cell range with another CellRef.  Copies
     * the given CellRef so it can set its own internal copy's
     * sheet name to null.
     * @param rangeEnd The CellRef indicating the end of the range
     *    of cells.
     */
    public void setRangeEndCellRef(CellRef rangeEnd)
    {
        myRangeEndCellRef = new CellRef(rangeEnd.getRow(), rangeEnd.getCol(),
                rangeEnd.isRowAbsolute(), rangeEnd.isColAbsolute());
    }

    /**
     * Returns the end of the cell range.  It has no sheet name.
     * @return The end of the cell range CellRef.
     */
    public CellRef getRangeEndCellRef()
    {
        return myRangeEndCellRef;
    }

    /**
     * Checks whether this cell reference range is equal to another object.
     * They are equal if:
     * 
    *
  • The other object is also a CellRefRange, the superclass * method equals returns true, and either both * have no range end CellRefs, or both range end * CellRefs compare equal. *
  • The other object is a CellRef but not a * CellRefRange, the superclass method equals * returns true, and this object does not have a range end * CellRef. *
* @param o The other object. */ @Override public boolean equals(Object o) { if (o instanceof CellRef) { if (o instanceof CellRefRange) { CellRefRange crr = (CellRefRange) o; return (super.equals(o) && (myRangeEndCellRef == null && crr.myRangeEndCellRef == null) || (myRangeEndCellRef != null && myRangeEndCellRef.equals(crr.myRangeEndCellRef))); } else { return (myRangeEndCellRef == null && super.equals(o)); } } return false; } /** * If there is a range end CellRef, then append a colon ":" * character followed by the range end formatted string. * @return The string representation of the range of cells. */ @Override public String formatAsString() { String superString = super.formatAsString(); if (myRangeEndCellRef == null) return superString; else return superString + ":" + myRangeEndCellRef.formatAsString(); } // No need to override other methods. }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy