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 toNumber method 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.String objects, such as CellText.String("11"), are converted to a numeric value by the toNumber method.

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 toString method 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.Number objects are converted to a string value by the toString method.