Skip to content

Cells

The LAY methods that work on the cells are:

LAY.getCellsCount()

Returns the number of cells in the layout of the document.

For example the instruction:

var nCells = LAY.getCellsCount();
returns the integer value 54 in the nCells variable.

Note

Cells count starts from 1.

LAY.getCell(cellIndex)

Returns the block of the cell with the given index, or undefined if the cell index is invalid.

Note

The cellIndex is not the id of the block, but is the index of the cell. It must be contained in the range [0, n], where n is the number of cells.

For example the instruction:

var cellBlock = LAY.getCell(4);

returns the following object in the cellBlock variable:

{
    "id": 13,
    "parent": 8,
    "pageNumber": 1,
    "type": "cell",
    "x0": 554,
    "y0": 344,
    "x1": 611,
    "y1": 359,
    "children": [],
    "beginPos": 199,
    "endPos": 206,
    "tokenBegin": 56,
    "tokenEnd": 57,
    "label": "",
    "cellIndex": 4,
    "tableIndex": 0,
    "row": 0,
    "col": 4,
    "rowSpan": 1,
    "colSpan": 1,
    "isHead": false,
    "isSpanned": false
}

The specific cell fields are:

Field name Description Field type Default value
cellIndex The position of the block in the index of the cells Integer -1
tableIndex The position of the block of the cell's table in the index of the tables Integer -1
row The row to which the cell belongs Integer -1
col The column to which the cell belongs Integer -1
rowSpan The number of rows on which the cell spans Integer -1
colSpan The number of columns on which the cell spans Integer -1
isHead Whether or not the cell belongs to the header of the table Boolean false
isSpanned Whether or not the cell is "covered" by another cell that spans over it Boolean false

Watch the Blocks fields to know about the common fields of this object.

LAY.getTableCell(tableIndex, row, column)

Returns the block of the cell at the given coordinates (row and column) of the selected table represented by its index, or undefined if the coordinates are invalid.

For example the instruction:

var tabCell = getTableCell(1, 2, 2);
returns in the tabCell the same object as in getCell(cellIndex) method but, of course, with different values:

{
    "id": 36,
    "parent": 21,
    "pageNumber": 1,
    "type": "cell",
    "x0": 267,
    "y0": 542,
    "x1": 375,
    "y1": 577,
    "children": [],
    "beginPos": 365,
    "endPos": 380,
    "tokenBegin": 98,
    "tokenEnd": 99,
    "label": "",
    "cellIndex": 26,
    "tableIndex": 1,
    "row": 2,
    "col": 2,
    "rowSpan": 1,
    "colSpan": 1,
    "isHead": false,
    "isSpanned": false
}

The LAY.getTableCell(table.tableIndex, r, c) could be used, for example, to navigate the tables and their cells:

function printTablesCells()
{
    var count = LAY.getTablesCount();   // retrieve the number of tables
    for (var t=0; t<count; t++) {
        var table = LAY.getTable(t);    // retrieve the table object
        CONSOLE.log("## TABLE "+t+" ##");
        for (var r=0; r<table.rows; r++) {  // iterate on rows and columns
            for (var c=0; c<table.cols; c++) {
                var cell = LAY.getTableCell(table.tableIndex, r, c);    // retrieve cell object at the current coordinates
                var cellText = LAY.getBlockText(cell.id);   // retrieve the content of the cell block
                CONSOLE.log("["+r+","+c+" "+cellText);
            }
        }
    }
}