ReoGrid
DOCUMENT
Rich Format Text

A rich format text is represented by class:

unvell.ReoGrid.Drawing.RichText

Rich format text can be displayed and printed when adding into cells or floating objects.

Display rich format text in cells

308

Code for above example:

var sheet = grid.CurrentWorksheet;

sheet.MergeRange("B2:F6");

sheet["B2"] = new Drawing.RichText()
  .Regular("The ")
  .Bold("Rich Text Format")
  .Regular(" (often abbreviated ")
  .Bold("RTF")
  .Regular(") is a proprietary")
  .Superscript("[6][7][8]")
  .Regular(" document file format with published specification developed by Microsoft Corporation from ")
  .Span("1987", textColor: Color.OrangeRed)
  .Span(" until ", textColor: Color.Black)
  .Span("2008", textColor: Color.OrangeRed)
  .Span(" for cross-platform document interchange with Microsoft products.", textColor: Color.Black);

Line breaks

Set cell style to make line word-break or break-all.

Example: Text without word break 311

Example: Text with word break 312

Code:

sheet.Cells["B2"].Style.TextWrap = TextWrapMode.WordBreak;

Text alignment

Set cell horizontal alignment and vertical alignment style to change rich text alignments. 313

Code:

sheet.Cells["B2"].Style.VAlign = ReoGridVerAlign.Middle;

Set text alignment to right: 314

Code:

sheet.Cells["B2"].Style.HAlign = ReoGridHorAlign.Right;

ReoGrid rich text structure

A simplest text

309

Use span method to add a text without any styles specified. For example:

sheet["B2"] = new Drawing.RichText()
  .Span("The Apple II (styled as apple ][) is an 8-bit home computer.");

The fastest way to change text styles is to use Bold, Italic, Regular etc. methods.

Bold

310

Code:

sheet["B2"] = new Drawing.RichText()
  .Span("The ")
  .Bold("Apple II")
  .Regular(" (styled as apple ][) is an 8-bit home computer.");

Use Bold method to make text bold, use Regular method to restore the text styles.

The usage of italic, underline, strikeout styles are same as bold.

Add paragraph (line break)

To break line, use NewLine method. 315

Code:

sheet["B2"] = new Drawing.RichText()
  .Span("The ")
  .Bold("Apple II")
  .Regular(" (styled as apple ][) is an 8-bit home computer.")
  .NewLine()
  .Span("One of the first highly successful mass-produced microcomputer products,[2] designed primarily by Steve Wozniak.");

Paragraph Spacing and Line Height

The NewLine method makes a new paragraph added into rich text. 316

It's possible to change the paragraph spacing and line height: 317

Use SetStyles method to change current styles of paragraph or span. 318

Code:

sheet["B2"] = new Drawing.RichText()
  .SetStyles(paragraphSpacing: 3.0f)
  .Span("The ")
  .Bold("Apple II")
  .Regular(" (styled as apple ][) is an 8-bit home computer.")
  .NewLine()
  .SetStyles(lineHeight: 2.0f)
  .Span("One of the first highly successful mass-produced microcomputer products,[2] designed primarily by Steve Wozniak.");

The SetStyles method changes current paragraph or span styles. The first SetStyles method change the paragraph spacing for first paragraph, before call the second SetStyles, since a NewLine method has been called, the second SetStyles method changes the line height for second paragraph.

Excel doesn't support adjust the paragraph spacing and line height styles.

Horizontal alignments for every paragraph

319

Code:

sheet["B2"] = new Drawing.RichText()
  .Span("The ")
  .Bold("Apple II")
  .Regular(" (styled as apple ][) is an 8-bit home computer.")
  .NewLine()
  .Span("One of the first highly successful mass-produced microcomputer products,[2] designed primarily by Steve Wozniak.")
  .NewLine()
  .SetStyles(halign: ReoGridHorAlign.Right)
  .Span("- wikipedia.org");

Excel doesn't support alignment styles for every paragraph (line).

Superscript and Subscript

To make a superscript, use Superscript method.

320

Code:

sheet["B2"] = new Drawing.RichText()
  .Span("The ")
  .Bold("Apple II")
  .Regular(" (styled as apple ][) is an 8-bit home computer.")
  .NewLine()
  .Span("One of the first highly successful mass-produced microcomputer products,")
  .Superscript("[2]")
  .Regular(" designed primarily by Steve Wozniak.")
  .NewLine()
  .SetStyles(halign: ReoGridHorAlign.Right)
  .Span("- wikipedia.org");

After use Superscript method, use Regular method to restore the text styles.

Display rich format text in drawing objects

To display rich form text in drawing objects, create the instance of RichText class, append text into it and set it into drawing objects.

Excel Import/Export Support

ReoGrid supports to import and export rich format text from/to Excel file. The below is an example of text displayed in both ReoGrid and Excel. 321


Was the content of the page helpful?

© 2012-2024UNVELL Inc.