Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically change size of comment box

I am able programmatically to add a comment to an Excel cell in C# using the Range.AddComment method:

range.Cells[1, 1].AddComment("Hello World!");

My problem is that some of the comments I need to add are quite long. During my testing, the comment box seems to remain at the default size regardless of how long the comment is. This means that the user cannot see all of the comment when they initially click the cell.

Is there a method I can use to have more control over how the comment is displayed so I can avoid this problem?

like image 502
TVOHM Avatar asked Oct 07 '15 16:10

TVOHM


1 Answers

Try this:

        Range cell = (Range)sheet.Cells[1, 1];
        Comment comment = cell.AddComment("blah");
        comment.Shape.TextFrame.AutoSize = true;

Edit: Longer text and different methods:

        string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n"+
            "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n nisi ut aliquip ex ea commodo consequat."+
            "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n"+
            "Excepteur sint occaecat cupidatat non proident, sunt in \nculpa qui officia deserunt mollit anim id est laborum";

        Range cell = (Range)sheet.Cells[1, 1];
        Comment comment = cell.AddComment();
        comment.Shape.TextFrame.AutoSize = true;
        comment.Text(text);
like image 81
Ric Gaudet Avatar answered Oct 18 '22 07:10

Ric Gaudet