ironpythonspotfire

How to get values from all the columns of the table in Spotfire using IronPython


I found an IronPython code to retrieve all the data for particular column or for multiple columns (explicitly defined) but I need to iterate tru all the data in an analysis and I wish to use a code that could let me do that without defining all the columns but to just handle all the rows of all tables.

EDIT: It seems I must clarify. There is a method of a table object: https://docs.tibco.com/pub/doc_remote/sfire-analyst/7.7.0/TIB_sfire-analyst_7.7.0_api/html/M_Spotfire_Dxp_Data_DataTable_GetRows.htm

DataTable. GetRows Method (DataValueCursor[] )

and what I need is to be able to pass a 'list/array/whatever' of cursors without knowing in advance how many columns each of the tables has.


Solution

  • You can traverse all tables, rows and columns using the code below.

    from Spotfire.Dxp.Data import *
    for eDataTable in Document.Data.Tables:
        for eColumn in eDataTable.Columns:
            for eTableRows in range(0,eDataTable.RowCount):
                print "Table: " + eDataTable.Name + "\tColumn: " + eColumn.Name +"\tRow: " + str(eTableRows) + "\tValue: " +eDataTable.Columns[eColumn.Name].RowValues.GetFormattedValue(eTableRows)
    

    EDIT

    Its a little cumbersome, but it looks like you can pass an array of cursors... something like this, which prints a table structure

    from Spotfire.Dxp.Data import *
    from System.Collections.Generic import List
    import System
    from System import Array
    for eTable in Document.Data.Tables:
        print "~~~~~~~~~~ " +eTable.Name+" ~~~~~~~~~~\n",
        CursList=[]
        ColList=[]
        for eColumn in eTable.Columns:
            CursList.append(DataValueCursor.Create(eTable.Columns[eColumn.Name]))
            ColList.append(eTable.Columns[eColumn.Name])
        CursArray = Array[DataValueCursor](CursList)
        for cName in range(ColList.Count):
            print str(ColList[cName])+"\t",
        print "\n",
        for row in eTable.GetRows(CursArray):
            for curs in range(CursList.Count):
                print str(CursList[curs].CurrentValue) + "\t",
            print "\n",