Subscribe Bookmark RSS Feed

How do you get the color of a specific cell in a data table using JSL?

txnelson

Super User

Joined:

Jun 22, 2012

I have a script where I need to determine what color specific cells in a data table have been set to.  I can find messages that can be sent to specific cells to color them, but my searches have failed to see anyway to retrieve the color of specific cells.  Does anyone have a solution?

Jim
2 REPLIES
ms

Super User

Joined:

Jun 23, 2011

The cell colors seem to be stored in a hierarchical list but I, too, can't find an easy way to access them.

Try something like this:

//Example table

dt=New Table( "test",

  Add Rows( 5 ),

  New Column( "X",

  Numeric,

  Continuous,

  Format( "Best", 12 ),

  Color Cells( {{38, {1}}, {9, {2}}, {74, {3, 4}}} ),

  Set Selected,

  Set Values( [1, 2, 3, 4, 5] )

  )

);

// Define function

get_cell_color = Function( {col, r},

  s = col << get script;

     //Locate argument "Color Cells" in column script

  For( i = 1, i <= N Arg( s ), i++,

  If( Head Name( Arg( s, i ) ) == "Color Cells",

  p = i;

  Break();

  )

  );

     //Identify the sublist that contains the color of row r

  L = Arg( Arg( s, p ), 1 );

  For( i = 1, N Items( L ), i++,

  If( N Row( Loc( L[i][2], r ) ) == 1,

  color = L[i][1];

  Break();

  )

  );

  color;

);

// Run function to find color of row four in first column

cellcolor = get_cell_color( Column( 1 ), 4 );

// Confirm..

New Window( "color",

  Spacer Box( size( 200, 100 ), color( cellcolor ) )

);


txnelson

Super User

Joined:

Jun 22, 2012

Thanks for the quick response. Function works well. I had to modify it a bit to handle the case where the all of the cells in a column have been set to the same color.

Jim Nelson,

Sent from Windows Mail

Jim