Package io.keikai.axyra.sheets
Class Range
java.lang.Object
io.keikai.axyra.sheets.Range
A rectangular block of cells — the bulk API. A
(Sheet, rect) view
holding no native resource; every read/write crosses JNI once for the
whole rectangle (never once per cell).
Reads come back via the structure-of-arrays codec and are reassembled into
CellValue[][] in pure Java; the numeric fast path
(numbers()) returns a primitive double[] directly.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intcontentFlags()bit: the cell carries a comment.static final intcontentFlags()bit: the cell carries a hyperlink.static final intcontentFlags()bit: the cell's text is rich (more than one run). -
Method Summary
Modifier and TypeMethodDescriptionvoidAttach a conditional-formatting rule to this rectangle.voidapplyNamedStyle(String name) Apply a previously registered named cell style to every cell in the rectangle.voidAuto-fill: detect a pattern in this range (linear numeric series, or a cyclic copy for text and mixed content) and extend it acrossdestination— Excel's fill-handle drag.intautoMerge(boolean horizontal) Auto-merge runs of adjacent cells with identical, non-empty content — left-to-right within each row whenhorizontalis true, otherwise top-to-bottom within each column.voidclear()Clear every cell in the rectangle (value and formula).intRemove every hyperlink in the rectangle, keeping the cell values.intcolCount()Number of columns in the rectangle.byte[]Row-major per-cell content flags — each entry is a bitwise OR ofCONTENT_COMMENT,CONTENT_HYPERLINKandCONTENT_RICH_TEXT(0 = none).voidCopy this rectangle to(dstRow, dstCol)ondstSheet(Excel's Copy → Paste).voidCopy this rectangle with an Excel Paste-Special mode:"all"/"values"/"formulas"/"formats"/"comments".voidcreateTable(String name, String... columnNames) Create a table (ListObject) over this rectangle.voiddeleteCells(Shift shift) Delete the rectangle's cells, shifting remaining cellsShift.UPorShift.LEFT.intFirst (left) column, 0-based inclusive.intfirstRow()First (top) row, 0-based inclusive.String[][]formulas()Read every cell's formula source.voidinsertCells(Shift shift) Insert blank cells over the rectangle, shifting existing cellsShift.DOWNorShift.RIGHT.intLast (right) column, 0-based inclusive.intlastRow()Last (bottom) row, 0-based inclusive.voidmerge()Merge the rectangle into a single cell.double[]numbers()Read the rectangle as a row-majordouble[].intremoveDuplicates(int[] keyColumns, boolean hasHeader) Remove duplicate rows in the rectangle, comparing the given key columns.introwCount()Number of rows in the rectangle.voidsetArrayFormula(String formula) Set a CSE (Ctrl+Shift+Enter) array formula over the whole rectangle, anchored at the top-left cell.voidsetFormula(String formula) Fill the rectangle with one formula, as Excel's Ctrl+Enter does: the formula is written for the top-left cell, and every other cell gets it with its relative references shifted by its offset from there (A1*B1onC1:C3becomesA2*B2in C2 andA3*B3in C3);$-anchored references stay put.voidsetFormulas(String[][] formulas) Write per-cell formulas (rowCount() x colCount()).voidsetNumbers(double[] data) Write the rectangle from a row-majordouble[]of lengthrowCount() * colCount().voidApply a style to every cell in the rectangle.voidsetValidation(Validation validation) Attach a data-validation rule to this rectangle.voidWrite every cell from aCellValue[][](row-major,rowCount() x colCount()).intThe 0-based index of the sheet this range belongs to.voidsort(int column, boolean ascending) Sort ascending/descending on a single column.voidSort the rectangle by one or more keys (first key is primary).voidsortLeftToRight(SortKey... keys) Sort left to right (Excel's Sort Options → "Sort left to right"): reorder whole columns within the rectangle by the values of one or more key rows.The A1 reference of the dynamic-array spill (or legacy CSE array) region containing this range's top-left cell — e.g.style()The style of the top-left cell of the rectangle.int[]styleIds()Row-major per-cell style ids (an engine-internal dedup index).voidunmerge()Unmerge any merged regions overlapping the rectangle.CellValue[][]values()Read every cell as aCellValue.
-
Field Details
-
CONTENT_COMMENT
public static final int CONTENT_COMMENTcontentFlags()bit: the cell carries a comment.- See Also:
-
CONTENT_HYPERLINK
public static final int CONTENT_HYPERLINKcontentFlags()bit: the cell carries a hyperlink.- See Also:
-
CONTENT_RICH_TEXT
public static final int CONTENT_RICH_TEXTcontentFlags()bit: the cell's text is rich (more than one run).- See Also:
-
-
Method Details
-
firstRow
public int firstRow()First (top) row, 0-based inclusive. -
firstColumn
public int firstColumn()First (left) column, 0-based inclusive. -
lastRow
public int lastRow()Last (bottom) row, 0-based inclusive. -
lastColumn
public int lastColumn()Last (right) column, 0-based inclusive. -
sheetIndex
public int sheetIndex()The 0-based index of the sheet this range belongs to. -
rowCount
public int rowCount()Number of rows in the rectangle. -
colCount
public int colCount()Number of columns in the rectangle. -
values
Read every cell as aCellValue. One JNI crossing; formula cells evaluate lazily on the engine side. -
numbers
public double[] numbers()Read the rectangle as a row-majordouble[]. Only numeric cells carry a value; every other cell (blank, text, bool, error) isNaN. One JNI crossing. -
setNumbers
public void setNumbers(double[] data) Write the rectangle from a row-majordouble[]of lengthrowCount() * colCount(). LikesetValues(io.keikai.axyra.sheets.CellValue[][]), this replaces values only: each cell keeps its style (number format, font, fill), comment and hyperlink, and a formula there is dropped. One JNI crossing. -
setValues
Write every cell from aCellValue[][](row-major,rowCount() x colCount()). Encodes to the SoA codec in pure Java, then one JNI crossing. Each cell's value is replaced and any formula cleared;CellValue.BLANKclears the cell. -
formulas
Read every cell's formula source. One JNI crossing. Entry isnullfor a non-formula cell, else the verbatim formula text (no leading "="). -
setFormula
Fill the rectangle with one formula, as Excel's Ctrl+Enter does: the formula is written for the top-left cell, and every other cell gets it with its relative references shifted by its offset from there (A1*B1onC1:C3becomesA2*B2in C2 andA3*B3in C3);$-anchored references stay put. UsesetFormulas(String[][])to give each cell its own text. One JNI crossing.- Throws:
AxyraFormulaException- if the formula is not valid
-
setFormulas
Write per-cell formulas (rowCount() x colCount()). Anullentry leaves the cell unchanged; an empty string clears it. One crossing. -
setArrayFormula
Set a CSE (Ctrl+Shift+Enter) array formula over the whole rectangle, anchored at the top-left cell. The engine spills the result across the range. One JNI crossing. -
copyTo
Copy this rectangle to(dstRow, dstCol)ondstSheet(Excel's Copy → Paste). Values, formulas, styles and comments are copied; relative references in formulas adjust by the paste offset, and dependents of the pasted cells recalculate. -
copyTo
Copy this rectangle with an Excel Paste-Special mode:"all"/"values"/"formulas"/"formats"/"comments". -
spillRange
The A1 reference of the dynamic-array spill (or legacy CSE array) region containing this range's top-left cell — e.g."A1:A3", or a single cell like"A1"for a 1x1 array result. Returnsnullwhen the cell is not part of an array region. Dynamic spills exist only after the anchor formula has evaluated (read the value or recalculate first). -
setStyle
Apply a style to every cell in the rectangle. The engine dedups identical styles, so this interns the style (one crossing) then assigns its id (one crossing). -
applyNamedStyle
Apply a previously registered named cell style to every cell in the rectangle. No-op ifnameis not registered. -
style
The style of the top-left cell of the rectangle. One JNI crossing pair. -
styleIds
public int[] styleIds()Row-major per-cell style ids (an engine-internal dedup index). One crossing. -
contentFlags
public byte[] contentFlags()Row-major per-cell content flags — each entry is a bitwise OR ofCONTENT_COMMENT,CONTENT_HYPERLINKandCONTENT_RICH_TEXT(0 = none). One JNI crossing: the bulk presence probe matchingCell.comment(),Cell.hyperlink()andCell.richRunCount(), so callers can locate the few cells carrying sidecar content without one crossing per cell. -
sort
Sort the rectangle by one or more keys (first key is primary). Sort-key columns are range-relative (0 = the range's first column). A key carrying a custom order sorts its matching values by list position (Excel's "Custom Lists"); unlisted values sort after all listed ones. -
sort
public void sort(int column, boolean ascending) Sort ascending/descending on a single column. -
sortLeftToRight
Sort left to right (Excel's Sort Options → "Sort left to right"): reorder whole columns within the rectangle by the values of one or more key rows. Each key'sSortKey.column()is the range-relative key row (0 = the range's first row); custom orders apply as insort(SortKey...). -
autoFill
Auto-fill: detect a pattern in this range (linear numeric series, or a cyclic copy for text and mixed content) and extend it acrossdestination— Excel's fill-handle drag. As in Excel, the destination must be on the same sheet, include this source range, and extend it along exactly one axis (same columns to fill down/up, or same rows to fill right/left). Source cells keep their values. -
removeDuplicates
public int removeDuplicates(int[] keyColumns, boolean hasHeader) Remove duplicate rows in the rectangle, comparing the given key columns. Key columns are range-relative (0 = the range's first column), as insort(SortKey...)and Excel's Remove Duplicates. Returns the number of rows removed.- Throws:
IllegalArgumentException- ifkeyColumnsis empty or a key column lies outside the range
-
setValidation
Attach a data-validation rule to this rectangle. -
addConditionalFormat
Attach a conditional-formatting rule to this rectangle. -
createTable
Create a table (ListObject) over this rectangle. With explicitcolumnNamesthe header row is set to those names; with none, the column names are read from this rectangle's own header row (row 1 of the range) — Excel's "Format as Table" over a range. Empty or duplicate headers fall back to generatedColumnNnames. -
merge
public void merge()Merge the rectangle into a single cell. -
unmerge
public void unmerge()Unmerge any merged regions overlapping the rectangle. -
autoMerge
public int autoMerge(boolean horizontal) Auto-merge runs of adjacent cells with identical, non-empty content — left-to-right within each row whenhorizontalis true, otherwise top-to-bottom within each column. Returns the number of regions created. -
insertCells
Insert blank cells over the rectangle, shifting existing cellsShift.DOWNorShift.RIGHT. -
deleteCells
Delete the rectangle's cells, shifting remaining cellsShift.UPorShift.LEFT. -
clearHyperlinks
public int clearHyperlinks()Remove every hyperlink in the rectangle, keeping the cell values. Returns the number of hyperlinks removed. One JNI crossing. -
clear
public void clear()Clear every cell in the rectangle (value and formula). One JNI crossing.
-