Show / Hide Table of Contents

Format Comments

Output: CommentsFormatting.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;
    
    //Border Color
    worksheet["A2"].AddComment("DR-IT", "Comment");
    this.SetProperties(worksheet,"A2");           
    worksheet["A2"].Comment.Line.Color = Color.Lime;

    //Border Transparency
    worksheet["A3"].AddComment("DR-IT", "Comment");
    this.SetProperties(worksheet, "A3");
    worksheet["A3"].Comment.Line.Color = Color.Red;
    worksheet["A3"].Comment.Line.Transparency = 0.5m;

    //Border Width
    worksheet["A4"].AddComment("DR-IT", "Comment");
    this.SetProperties(worksheet, "A4");
    worksheet["A4"].Comment.Line.WidthPoints = 5;

    //Fill Color
    worksheet["A5"].AddComment("DR-IT", "Comment");
    this.SetProperties(worksheet, "A5");
    worksheet["A5"].Comment.Fill.Color = Color.Yellow;

    //Fill Gradient Darken
    worksheet["A6"].AddComment("DR-IT", "Comment");
    this.SetProperties(worksheet, "A6");
    worksheet["A6"].Comment.Fill.Color = Color.Red;
    worksheet["A6"].Comment.Fill.Type = CommentFillEffect.Gradient;
    worksheet["A6"].Comment.Fill.Gradient.DarkenPercentage = 0.6m;
    
    workbook.SaveAs("CommentsFormatting.xlsx");
}

private void SetProperties(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;
}
Back to top Generated by DocFX