2015-10-07 38 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;