Using Cell Values in Expressions (Python)
Once a cell's value has been set, it can be accessed and used to
specify the value for another cell. Cell values are stored as CellText.Number or CellText.String objects. To use a cell value in an expression,
you obtain a string or numeric representation of the value using the toString
or toNumber method.
Example: Numeric Representations of Cell Values
from spss import CellText
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
table.Append(spss.Dimension.Place.row,"row dimension")
table.Append(spss.Dimension.Place.column,"column dimension")
row_cat1 = CellText.String("first row")
row_cat2 = CellText.String("second row")
col_cat1 = CellText.String("first column")
col_cat2 = CellText.String("second column")
table[(row_cat1,col_cat1)] = CellText.Number(11)
cellValue = table[(row_cat1,col_cat1)].toNumber()
table[(row_cat2,col_cat2)] = CellText.Number(2*cellValue)
- The
toNumbermethod is used to obtain a numeric representation of the cell with category values("first row","first column"). The numeric value is stored in the variable cellValue and used to specify the value of another cell. - Character representations of numeric values stored
as
CellText.Stringobjects, such asCellText.String("11"), are converted to a numeric value by thetoNumbermethod.
Example: String Representations of Cell Values
from spss import CellText
table = spss.BasePivotTable("Table Title",
"OMS table subtype")
table.Append(spss.Dimension.Place.row,"row dimension")
table.Append(spss.Dimension.Place.column,"column dimension")
row_cat1 = CellText.String("first row")
row_cat2 = CellText.String("second row")
col_cat1 = CellText.String("first column")
col_cat2 = CellText.String("second column")
table[(row_cat1,col_cat1)] = CellText.String("abc")
cellValue = table[(row_cat1,col_cat1)].toString()
table[(row_cat2,col_cat2)] = CellText.String(cellValue + "d")
- The
toStringmethod is used to obtain a string representation of the cell with category values("first row","first column"). The string value is stored in the variable cellValue and used to specify the value of another cell. - Numeric values stored as
CellText.Numberobjects are converted to a string value by thetoStringmethod.