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.

Syntax

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.

Examples

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:

G = NewGrid(3,5)

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

t = {2,3,4,5,6,7}

-- create a table of data

G:Set(t)

-- store data in the grid starting at (1,1)

Printf("cell = %lg", G:Get(1,3) )

-- result: cell = 4

This script initializes the entire grid to 52.5:

G = NewGrid(3,5)

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

G:Set( 52.5 )

-- store the same value in the entire grid

Printf("cell = %lg", G:Get(3,4) )

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

G = NewGrid(4,10)

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

G:Set( 52.5 )

-- set 52.5 into all cells of the grid

Printf("cell = %lg", G:Get(2,3) )

-- result: cell = 52.5

t = {1,2,3,4,5,6,7,8,9,10,11,12}

-- create a table of data

G:Set( t, NewRect(2,4,2,3) )

-- store array into 3 columns of 2 rows

Printf("cell = %lg", G:Get(2,3) )

-- result: cell = 4

G:Set( 22.6, 2, 3 )

-- save 22.6 into the same column,row

Printf("cell = %lg", G:Get(2,3) )

-- result: cell = 22.6

Related Topics

Get

SetCol

SetRow

CGrid class