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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With