CGrid:Get


The Get method returns the value in the grid cell at (column, row) or a rectangular region of columns and rows.

Syntax

array = G:Get()

array = G:Get( CRect )

sValue = G:Get( nCol, nRow )

where

    If no arguments are passed, the entire grid is returned as an array of length GetNumCols() * GetNumRows().

    CRect is a CRect object specifying the indices for the minimum, maximum columns and minimum, maximum rows to retrieve. The data are returned in an array of length (CRect:Width() + 1) * (CRect:Height() + 1).

    nCol, nRow are the column and row indices of the cell to retrieve.

    array is a Lua array containing the returned grid data. On failure, nil is returned.

    sValue is a string containing the single value returned from the cell at nCol, nRow. On failure, 0 is returned.

Examples

The following script creates a grid and stores numbers in columns 1 through 3 and rows 1 through 2. The script retrieves data from all of row 3:

G = NewGrid(3,2)

-- new grid with 3 cols, 10 rows, 1 Sheet

G:SetRow( {2,3,4}, 1 )

-- set 5 columns in row 1

G:SetRow( {4,5,6}, 2 )

-- set 5 columns in row 2

t = G:Get()

-- fetch data from row 3

for i = 1,#t do

-- do for each row

  Printf("%lg, ", t[i] )

-- result: 2, 3, 4, 4, 5, 6

end

 

The following script creates a grid like the one above and retrieves columns 2 and 3 of rows 1 and 2:

G = NewGrid(3,2)

-- new grid with 3 cols, 10 rows, 1 Sheet

G:SetRow( {2,3,4}, 1 )

-- set 5 columns in row 1

G:SetRow( {4,5,6}, 2 )

-- set 5 columns in row 2

t = G:Get( NewRect(2,3,1,2) )

-- get row 3, starting at column 2

for i = 1,#t do

-- do for each column

  Printf("%lg, ", t[i] )

-- result: 3, 4, 5, 6

end

 

The following script creates a grid like the one above and retrieves the value at columns 2, row 2:

G = NewGrid(3,2)

-- new grid with 3 cols, 10 rows, 1 Sheet

G:SetRow( {2,3,4}, 1 )

-- set 5 columns in row 1

G:SetRow( {4,5,6}, 2 )

-- set 5 columns in row 2

v = G:Get( 2, 2 )

-- get row 3, starting at column 2

Printf("str = %s", v )

-- result: str = 5

Printf("num = %lg", v )

-- result: num = 5

Related Topics

Set

GetCol

GetRow

CGrid class