Add Comment with rich text contents
Output: CommentsRichText.xlsx
public void Run()
{
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
worksheet.GetRange("A1:A10").SetRowsHeight(60);
worksheet.Columns["A"].WidthPixels = 100;
worksheet.Columns["B"].WidthPixels = 100;
var richText = new RichTextParagraph();
richText.Runs.Add(new RichTextRun(){FontName = "Arial",FontSize = 10,Foreground = SpreadsheetColor.Red,Text = "Arial 10 Red"});
richText.Runs.Add(new RichTextRun() { FontName = "Cambria", FontSize = 6, Foreground = SpreadsheetColor.Green, Text = "Cambria 6 Green" });
worksheet["A2"].AddComment("DR-IT", richText);
this.FormatComment(worksheet, "A2");
workbook.SaveAs("CommentsRichText.xlsx");
}
private void FormatComment(Worksheet worksheet,string label)
{
worksheet[label].Comment.Size.WidthPixels = 80;
worksheet[label].Comment.Size.HeightPixels = 50;
//Anchor the comment shape one row above and one column to the left
worksheet[label].Comment.AnchoredCell = worksheet[worksheet[label].Row.Index - 1, worksheet[label].Column.Index + 1];
//Always show the comment
worksheet[label].Comment.Visible = true;
}