Jump to content
We've recently updated our Privacy Statement, available here. ×

Script to iterate over all columns


V S

Recommended Posts

Hi,

I am trying to write a script to iterate over all the columns in a data table.

from Spotfire.Dxp.Data import *

dataTable = Document.Data.Tables["Test"]

print dataTable.Name

cursor = DataValueCursor.CreateFormatted(dataTable.Columns["ColumnA"])

valList = List [str]();

#iterate through table column rows to retrieve the values

for row in dataTable.GetRows(cursor):

value = cursor.CurrentValue

if value str.Empty:

valList.Add(value)

Using above code, it means I have to create a cursor object for each column and create for loop for each cursor object

Is there a better way to loop through all columns and do necessary operations

Thanks for help.

Link to comment
Share on other sites

To read row values of a column, you will have to create the respective cursor. In this case you will have to create a cursor for each column to read the values of that column.

Also you don't have to create a separate loop for each column, you can just specify all the cursors in the dataTable.GetRows(cursor,cursor1) , something asbelow

cursor = DataValueCursor.CreateFormatted(dataTable.Columns["ColumnA"])

cursor1 = DataValueCursor.CreateFormatted(dataTable.Columns["ColumnB"])

valList = List [str]();

#iterate through table column rows to retrieve the values

for row in dataTable.GetRows(cursor,cursor1):

value = cursor.CurrentValue

if value str.Empty:

valList.Add(value)

Link to comment
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...