Skip to content

Cells

The LAY methods that work on the cells are:

getCellsCount

The getCellsCount method returns the number of cells in the layout of the document.

For example the instruction:

var nCells = LAY.getCellsCount();
sets a variable called nCells that, considering the Extract example output described in the dedicated page, is set to the value of 54.

Note

Cell count starts from 1.

The syntax is:

LAY.getCellsCount()

getCell

The getCell method returns the block of the cell with the given index, or undefined if the cell index is invalid.

For example, considering the Extract example output introduced in the dedicated page, the instruction:

var cellBlock = LAY.getCell(4);

sets a cellBlock variable whose value is the following object representing the table cell with index 4:

{
    "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.

The syntax is:

LAY.getCell(cellIndex)

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

getTableCell

The getTableCell method 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, considering the Extract example output introduced in the dedicated page, the instruction:

var tabCell = getTableCell(1, 2, 2);

sets a tabCell variable whose value is the same object as in the 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 getTableCell method 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);
            }
        }
    }
}

The syntax is:

LAY.getTableCell(tableIndex, row, column)

where:

  • tableIndex is the table index.
  • row is the row index
  • column is the column index.