xlsgen > overview > Rich Formatting

Rich formatting is the ability to use more than one formatting within a cell or merged cells. This capability breaks the inherent limitations of a grid-based cell formatting, as in the example below :


Rich formatting only applies to labels. If you have numbers, dates, or anything else, then make sure to translate it to a label if you want to take advantage of it.

A rich formatting object is exposed by the current worksheet. See the IXlsWorksheet for more information. A rich formatting object must be created first.

A rich formatting provides the ability to iteratively associate a label and a formatting style. That label is a fraction of what makes the full label that gets eventually showed in the cell.

Once the rich label properties are set, the rich label object can be passed onto the current worksheet, in any cell. Or it can be passed to a merged cells object. See IXlsMergedCells for more information.

All those styles must be created first. Styles are either created from the current worksheet, or derived from other styles by duplicating them. See IXlsWorksheet and IXlsStyle for more information.

There is a restriction on styles. Only the font properties are taken into account. See the IXlsFont for more information.

In order to produce the example above, the following code is required :

VB code

Dim style As IXlsStyle
Set style = wksht.NewStyle
style.Font.Size = 14
style.Font.Bold = True
style.Font.Color = colorBlue

style.Apply

Dim style2 As IXlsStyle
Set style2 = style.Duplicate
style2.Font.Color = colorRed
style2.Font.Italic = True

Dim rl As IXlsRichLabel
Set rl = wksht.NewRichLabel
rl.Label "hello ", style
rl.Label "world!", style2
wksht.RichLabel(4, 3) = rl

wksht.ColWidth(3) = 20

C# code

IXlsStyle style = wksht.NewStyle();
style.Font.Size = 14;
style.Font.Bold = 1;
style.Font.Color = (int) xlsgen.enumColorPalette.colorBlue;

style.Apply();

IXlsStyle style2 = style.Duplicate();
style2.Font.Color = (int) xlsgen.enumColorPalette.colorRed;
style2.Font.Italic = 1;

IXlsRichLabel rl = wksht.NewRichLabel();
rl.Label("hello ", style);
rl.Label("world!", style2);
wksht.set_RichLabel(4, 3, rl);

wksht.set_ColWidth(3, 20);

C/C++ code

xlsgen::IXlsStylePtr style = wksht->NewStyle();
style->Font->Size = 14;
style->Font->Bold = TRUE;
style->Font->Color = xlsgen::colorBlue;

style->Apply();

xlsgen::IXlsStylePtr style2 = style->Duplicate();
style2->Font->Color = xlsgen::colorRed;
style2->Font->Italic = TRUE;

xlsgen::IXlsRichLabelPtr rl = wksht->NewRichLabel();
rl->Label("hello ", style);
rl->Label("world!", style2);
wksht->RichLabel[4][3] = rl;

wksht->ColWidth[3] = 20;

 

xlsgen documentation. © ARsT Design all rights reserved.