Search in sources :

Example 51 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class XSSFSheet method getTopRow.

/**
     * The top row in the visible view when the sheet is
     * first viewed after opening it in a viewer
     *
     * @return integer indicating the rownum (0 based) of the top row
     */
@Override
public short getTopRow() {
    String cellRef = getSheetTypeSheetView().getTopLeftCell();
    if (cellRef == null) {
        return 0;
    }
    CellReference cellReference = new CellReference(cellRef);
    return (short) cellReference.getRow();
}
Also used : CellReference(org.apache.poi.ss.util.CellReference)

Example 52 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class XSSFSheet method getReferenceBuiltInRecord.

private static String getReferenceBuiltInRecord(String sheetName, int startC, int endC, int startR, int endR) {
    // Excel example for built-in title:
    //   'second sheet'!$E:$F,'second sheet'!$2:$3
    CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
    CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
    CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
    CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
    String escapedName = SheetNameFormatter.format(sheetName);
    String c = "";
    String r = "";
    if (startC != -1 || endC != -1) {
        String col1 = colRef.getCellRefParts()[2];
        String col2 = colRef2.getCellRefParts()[2];
        c = escapedName + "!$" + col1 + ":$" + col2;
    }
    if (startR != -1 || endR != -1) {
        String row1 = rowRef.getCellRefParts()[1];
        String row2 = rowRef2.getCellRefParts()[1];
        if (!row1.equals("0") && !row2.equals("0")) {
            r = escapedName + "!$" + row1 + ":$" + row2;
        }
    }
    StringBuilder rng = new StringBuilder();
    rng.append(c);
    if (rng.length() > 0 && r.length() > 0) {
        rng.append(',');
    }
    rng.append(r);
    return rng.toString();
}
Also used : CellReference(org.apache.poi.ss.util.CellReference)

Example 53 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class XSSFSheet method setAutoFilter.

@SuppressWarnings("resource")
@Override
public XSSFAutoFilter setAutoFilter(CellRangeAddress range) {
    CTAutoFilter af = worksheet.getAutoFilter();
    if (af == null) {
        af = worksheet.addNewAutoFilter();
    }
    CellRangeAddress norm = new CellRangeAddress(range.getFirstRow(), range.getLastRow(), range.getFirstColumn(), range.getLastColumn());
    String ref = norm.formatAsString();
    af.setRef(ref);
    XSSFWorkbook wb = getWorkbook();
    int sheetIndex = getWorkbook().getSheetIndex(this);
    XSSFName name = wb.getBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
    if (name == null) {
        name = wb.createBuiltInName(XSSFName.BUILTIN_FILTER_DB, sheetIndex);
    }
    name.getCTName().setHidden(true);
    CellReference r1 = new CellReference(getSheetName(), range.getFirstRow(), range.getFirstColumn(), true, true);
    CellReference r2 = new CellReference(null, range.getLastRow(), range.getLastColumn(), true, true);
    String fmla = r1.formatAsString() + ":" + r2.formatAsString();
    name.setRefersToFormula(fmla);
    return new XSSFAutoFilter(this);
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) CellReference(org.apache.poi.ss.util.CellReference)

Example 54 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class XSSFSheet method getLeftCol.

@Override
public short getLeftCol() {
    String cellRef = worksheet.getSheetViews().getSheetViewArray(0).getTopLeftCell();
    if (cellRef == null) {
        return 0;
    }
    CellReference cellReference = new CellReference(cellRef);
    return cellReference.getCol();
}
Also used : CellReference(org.apache.poi.ss.util.CellReference)

Example 55 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class XSSFSheet method getPaneInformation.

/**
     * Returns the information regarding the currently configured pane (split or freeze).
     *
     * @return null if no pane configured, or the pane information.
     */
@Override
public PaneInformation getPaneInformation() {
    CTPane pane = getDefaultSheetView().getPane();
    // no pane configured
    if (pane == null) {
        return null;
    }
    CellReference cellRef = pane.isSetTopLeftCell() ? new CellReference(pane.getTopLeftCell()) : null;
    return new PaneInformation((short) pane.getXSplit(), (short) pane.getYSplit(), (short) (cellRef == null ? 0 : cellRef.getRow()), (cellRef == null ? 0 : cellRef.getCol()), (byte) (pane.getActivePane().intValue() - 1), pane.getState() == STPaneState.FROZEN);
}
Also used : PaneInformation(org.apache.poi.ss.util.PaneInformation) CellReference(org.apache.poi.ss.util.CellReference)

Aggregations

CellReference (org.apache.poi.ss.util.CellReference)125 Test (org.junit.Test)52 Cell (org.apache.poi.ss.usermodel.Cell)28 Row (org.apache.poi.ss.usermodel.Row)27 AreaReference (org.apache.poi.ss.util.AreaReference)20 Sheet (org.apache.poi.ss.usermodel.Sheet)18 Workbook (org.apache.poi.ss.usermodel.Workbook)14 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)13 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)12 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)11 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)8 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)8 CellStyle (org.apache.poi.ss.usermodel.CellStyle)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)5 RichTextString (org.apache.poi.ss.usermodel.RichTextString)5 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4