CGrid:Set
The Set method saves one or more values in the grid at (column, row) or in a rectangular region of columns and rows.
bSuccess = G:Set( value )
bSuccess = G:Set( array )
bSuccess = G:Set( array, CRect )
bSuccess = G:Set( sValue, nCol, nRow )
where
value is a number or string that can be converted to a number. The value is saved to the entire table.
array is a Lua array containing the returned grid data to save.
CRect is a CRect object specifying the indices for the minimum, maximum columns and minimum, maximum rows to save.
nCol, nRow are the column and row indices of the single cell.
bSuccess is the returned success code. On success it is true, otherwise false.
The following script creates a grid and stores numbers in columns 1 through 3 and rows 1 through 2. The grid has more columns, but the end of the data array is reached before the end of the grid:
|
-- new grid with 3 cols, 10 rows, 1 Sheet |
|
-- create a table of data |
|
-- store data in the grid starting at (1,1) |
|
-- result: cell = 4 |
This script initializes the entire grid to 52.5:
|
-- new grid with 3 cols, 10 rows, 1 Sheet |
|
-- store the same value in the entire grid |
|
-- result: cell = 52.5 |
The following script creates a grid and uses various methods to store data into the grid. The first method sets the entire table. Then an array of 12 numbers is saves into the rectangle [2:4,2:3]. Since the rectangle defines only 2 rows of 3 columns of grid indices, only the first 6 array elements are used. Finally, one cell is set. Each time, the same cell value is retrieved to show how it changes.
|
-- new grid with 3 cols, 10 rows, 1 Sheet |
|
-- set 52.5 into all cells of the grid |
|
-- result: cell = 52.5 |
|
-- create a table of data |
|
-- store array into 3 columns of 2 rows |
|
-- result: cell = 4 |
|
-- save 22.6 into the same column,row |
|
-- result: cell = 22.6 |