Cell with multiple text styles

Hi,

In Excel, it is possible to have both regular and bold text in the same cell.

How is this handled in Flexcel.NET ? Is it possible to get/set different font style from the Flexcel API ?

Thanks

Yes, rich text is fully supported in FlexCel. You need to enter a TRichString, but as always, APIMate is your friend.

Format the text in Excel, open it in ApiMate, and see the code. For example, this is what I get for "hello world", with "world" in bold:

   TRTFRun[] Runs;
    Runs = new TRTFRun[1];
    Runs[0].FirstChar = 5;
    TFlxFont fnt;
    fnt = xls.GetDefaultFont;
    fnt.Style = TFlxFontStyles.Bold;
    Runs[0].FontIndex = xls.AddFont(fnt);

    //Set the cell values
    xls.SetCellValue(1, 1, new TRichString("Hello World", Runs, xls));
    //We could also have used: xls.SetCellFromHtml(1, 1, "Hello<b> World</b>")

As the comment from APIMate says, you could use SetCellFromHtml if you prefer. If not, just construct a TRichString by specifying positions and fonts for each position.

To get the value instead of setting it, it is the reverse. You can check if GetCellValue returns a TRichString, or use GetHtmlFromCell if you prefer html encoding.

Regards,
   Adrian.