Different types of Format for Excel Comment?
- Resize/Auto fit of Comment. (We already discussed in Part 9(A))
- Add Text a Background Color in Comment. (We already discussed in Part(A))
- Set Text Alignments in Comment. (We already discussed in Part 10(B))
- Set Font Style in Excel Comment (We already discussed in Part 10(B))
- Add Rich Text in Excel Comment. (We already discussed in Part 11(C))
- Add Multiple Rich Text in Excel Comment. (We already discussed in Part 11(C))
- Remove Rich Text in Excel Comment. (We already discussed in Part 11(C))
- Multi Style Excel Cell & Comment Text using ExcelRichTextCollection Class.
- Set Line or Border Style in a Comment. (We will discuss on Part 13(E))
What is ExcelRichTextCollection Class?
ExcelRichTextCollection class is a collection, containing the ExcelRichText objects. This class belongs to OfficeOpenXml.Style namespace.
This class has five important methods, these are,
By using this property, we assign specific
ExcelRichText object by it's index position.
How to Add Multi Style Text in Excel Cell using EPPlus?
ExcelRange Class has property
RichText (if you don't know what is
ExcelRange Class, please watch my previous video
Part-1 first). This
RichText property is the type of
ExcelRichTextCollection class.
First, we assign
Rng.RichText property to the object of
ExcelRichTextCollectionClass. Here,
Rng is the object of
ExceRange class &
RichTxtCollection is the object of
ExcelRichTextCollection class.
*After that, we use
Add() method of
ExcelRichTextCollection class for adding String text for individually applied each RichText style. We assign this Collection object to the
ExcelRichText class object. Here,
RichText is the object of ExcelRichText class. Using this object property, we set different styles in the text.
Please see this below code.
- using(ExcelRange Rng = wsSheet1.Cells["B5"]) {
- Rng.Style.Font.Size = 20;
-
- ExcelRichTextCollection RichTxtCollection = Rng.RichText;
- ExcelRichText RichText = RichTxtCollection.Add("H");
- RichText.Color = Color.Red;
- RichText.Italic = true;
-
- RichText = RichTxtCollection.Add("2");
-
- RichText.Color = Color.Red;
- RichText.Italic = true;
- RichText.VerticalAlign = ExcelVerticalAlignmentFont.Subscript;
- RichText = RichTxtCollection.Add("O");
- RichText.Color = Color.Red;
- RichText.Italic = false;
- RichText = RichTxtCollection.Add(" & ");
- RichText.Color = Color.Black;
- RichText.Italic = false;
- RichText = RichTxtCollection.Add("E=MC");
- RichText.Color = Color.Blue;
- RichText.Italic = false;
- RichText = RichTxtCollection.Add("2");
- RichText.Color = Color.Blue;
- RichText.Italic = false;
- RichText.VerticalAlign = ExcelVerticalAlignmentFont.Superscript;
-
- }
How to Add Multi Style in Excel Comment Text Using EPPlus?
We have seen in
Part-11(C) of this video series that the RichText property of ExcelComment class object can create individual ExcelRichText class object & add those objects as a collection object. This Collection Object is nothing but an ExcelRichTextCollection class because the RichText property is the type of ExcelRichTextCollecion class. So, ExcelRichTextCollecion class is indirectly involved by the ExcelComment class.