2015-10-07 47 views
1

我能够以编程方式在C#中使用Range.AddComment方法的注释添加到Excel单元格:编程方式更改尺寸

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

我的问题是,一些我需要补充的意见是相当长。在我的测试过程中,评论框似乎保持默认大小,无论评论的时间长短。这意味着用户最初单击单元格时不能看到所有评论。

有没有一种方法可以用来更好地控制评论的显示方式,所以我可以避免这个问题?

回答

4

试试这个:

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

编辑:较长的文本和不同的方法:

 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); 
+0

谢谢 - 这正是我一直在寻找的。 – TVOHM

0

我不得不用自动调整解决它,而不是。

worksheet.Cells[1, i + 1].AddComment("Lorem ipsum dolor sit amet\nSed do eiusmod", ""); 
worksheet.Cells[1, i + 1].Comment.AutoFit = true;