簡體   English   中英

以編程方式更改評論框的大小

[英]Programmatically change size of comment box

我可以使用Range.AddComment方法以編程方式在C#中向Excel單元格添加注釋:

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

我的問題是我需要添加的一些評論很長。 在我的測試過程中,無論評論有多長,評論框似乎都保持默認大小。 這意味着用戶在最初單擊單元格時無法看到所有注釋。

有沒有一種方法可以用來更好地控制注釋的顯示方式,這樣我可以避免這個問題?

嘗試這個:

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

我不得不用自動調整解決它。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM