Fill Extracted Data Cells with Color

Version Info

Minimum Origin Version Required: Origin 8.0 SR0


The following example shows how to find cells with LabTalk testing condition expression from a worksheet. And then fill these cells with specified color, also set the font color.


In the example, the string variable strLTRunBeforeLoop is used to set LabTalk script command before running the testing condition. Here it is defined as each column dynamically in the for-loop. The strCondition is used to specified LabTalk testing condition expression.

Before running this example, run the function Before_Running first to create a worksheet with uniform data.

void Fill_Cell_Color()
        Worksheet wks = Project.ActiveLayer(); // get the active worksheet
        if(!wks)   // if the active worksheet not exist, return
        int nNumCols = wks.GetNumCols();    // get column number
        DataRange dr;   // data range to hold the items which satisfy condition
        // loop each column to find those items that satisfy the condition
        for(int nCol=0; nCol<nNumCols; nCol++)
                // LabTalk script to be executed before the looping start
                string strLTRunBeforeLoop = "range a = " + (string)(nCol+1);   // define each column range for LabTalk
                // LabTalk conditional expression involving columns in the worksheet
                string strCondition = "a>=0.2 && a<=0.6";
                vector<uint> vuRowIndices;   // vector for row indices
                // get the row indices which satisfy the condition
                int nNumRowIndices = wks.SelectRows(strCondition, vuRowIndices, 0, -1, -1, strLTRunBeforeLoop);
                if(nNumRowIndices==0)    // no item satisfies the condition
                        // add those items, which satisfy the condition, to the data range
                        for(int nRowIndex=0; nRowIndex<vuRowIndices.GetSize(); nRowIndex++)
                                dr.Add("", wks, vuRowIndices[nRowIndex], nCol, vuRowIndices[nRowIndex], nCol);

        Tree trFormat;    // define format tree
        trFormat.Root.CommonStyle.Fill.FillColor.nVal = SYSCOLOR_RED;   // fill color = red
        trFormat.Root.CommonStyle.Color.nVal = SYSCOLOR_BLUE; // font color = blue
        if(0==dr.UpdateThemeIDs(trFormat.Root))   // no error
                bool bRet = dr.ApplyFormat(trFormat, true, true);   // return true if apply format successfully
void Before_Running()
        // prepare worksheet with data to do extract
        Worksheet wks;
        wks.SetSize(30, 5); // set worksheet with 3o rows and 5 columns  
        // set uniform data for all columns
        for(int nCol=0; nCol<wks.GetNumCols(); nCol++)
                Dataset ds(wks, nCol);