RTFRuns woes

I am using FlexCel under BCB6 updating a legacy application.  I use the component extensively to parse content from  .xls files created by our manufacturing software, so I am familiar with basic usage and operation.  


Recently, I attempted to make use of the RTFRunList to determine if a cell contains text formatted using strikeout font, using the method below.  

//---------------------------------------------------------------------------
//  Excluded() --  Return true if cell contains strikeout text
//---------------------------------------------------------------------------

bool Excluded(TFlexCelImport *xl, int row, int col)
{
    WideString s1 = xl->CellValue[row][col];
    TFlxFont F;
    TRTFRunList list;
    list = xl->RTFRuns[row][col];
    int len = list.Length;
    for (int i = 0; i < len; ++i)
        {
        xl->GetFontList(list.FontIndex, F);
        if (F.Style.Contains(flsStrikeOut))
            return true;
        }

    return false;
}

For some reason, even when processing cells within a worksheet which are known to contain strikeout and other formatting (such as colorized text), RTFRuns[row][col]; always returns an empty list.  I have stepped through the code above and inspected s1, to insure that it matches the (text) value of the relevant cell and inspection of that cell in Excel verifies that the cell contents are formatted.  

Any ideas?   

Hi,

Before digging deeper, let me first say that a cell might have font formatting (like strikeout) and not have RTFRuns.  
There are 2 things that affect the font of the cell:
1)The font assigned to the cell
2) The font assigned to the string itself. (Those are the RTFRuns).

RTFRuns are almost never used, they only are used when you have say half the text of a cell in bold, and the other half not in bold. You can't do this with with a global cell  Font and that's why we need RTFRuns.

In Excel, if you go to a cell and press the "Bold" icon, the cell font will change, but there will be no RTFRuns. On the other hand (and this can be confusing sometimes) if you edit the text, select it all, and press bold, then the format in the cell won't change, but you will have an RTFRun.

So in addition to checking RTFRuns, I would also check for the Font in the cell in the Excluded method:

bool Excluded(TFlexCelImport *xl, int row, int col)
{
TFlxFormat fm;
xl->GetCellFormatDef(row, col, fm);
if (fm.Font.Style.Contains(flsStrikeOut)) return true;


WideString s1 = xl->CellValue[row][col];
    TFlxFont F;
    TRTFRunList list;
    list = xl->RTFRuns[row][col];
    int len = list.Length;
    for (int i = 0; i < len; ++i)
        {
        xl->GetFontList(list.FontIndex, F);
        if (F.Style.Contains(flsStrikeOut))
            return true;
        }

    return false;
}

This will detect both when the cell format is strikeout, or when the cell format isn't but some part of the string in the cell is striked out. You can check it it with a simple Excel file, by formatting a full cell and a part of it, and you will see it enters both branches of the code.

Regards,
   Adrian.



Thank you for the helpful and prompt response.  My code is now working.