Search code examples
ironpythonspotfiretibco

Update/Remove Calculated Column using IronPython


I'm using Spotfire and would like to know if there's a way of updating or removing a calculated column using IronPython code.

Ex: Let's pretend I have a table with: | Column 1 | Column 2| Column 3 | Calculated Column |

So, every time I run a specific script, I want it to change the values of the calculated Column.

PS: I already have the below code to create the column if needed. So, if there is at least a way of deleting the column, it would also work for me.

from Spotfire.Dxp.Data import CalculatedColumn

newColName = "MY_CALCULATED_COLUMN"
newColExpr = "TRIM([myTableCol])"
Document.Data.Tables["MY_TABLE"].Columns.AddCalculatedColumn(newColName,newColExpr).As[CalculatedColumn]()

Solution

  • the following code will work for you:

    newColName = "col"
    Document.Data.Tables["Data Table"].Columns.Remove(newColName)
    

    (you don't need to import any classes for this one)

    you can find additional info in the API documentation.