如何添加評論
在 Excel 中,註解是一種可以添加到儲存格的備註或注釋,以提供額外的資訊而不影響儲存格的實際內容。註解對於提供數據或計算的解釋、上下文或提醒非常有用。
如何添加評論
- 下載 C# 函式庫以啟用評論功能
- 打開現有或建立新的 Excel 試算表
- 使用
新增評論
新增評論的方法 - 通過訪問來檢索和編輯評論 評論 屬性
- 使用此工具從單元格中移除註解
Remove評論
方法
立即開始在您的專案中使用IronPDF,並享受免費試用。
查看 IronXL 上 Nuget 快速安裝和部署。已被下載超過800萬次,它正用C#改變Excel。
Install-Package IronXL.Excel
請考慮安裝 IronXL DLL 直接下載並手動安裝到您的專案或GAC表單: IronXL.zip
手動安裝到您的項目中
下載DLL添加評論範例
選擇單元格並使用 AddComment
方法向單元格添加評論。默認情況下,評論將是不可見的。將滑鼠懸停在單元格上即可查看不可見的評論。
:path=/static-assets/excel/content-code-examples/how-to/add-comment-add-comment.cs
using IronXL;
using System.Linq;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
Cell cellA1 = workSheet["A1"].First();
Cell cellD1 = workSheet["D1"].First();
// Add comments
cellA1.AddComment("Hello World!", "John Doe"); // Add comment with content and author. The comment is invisible by default.
cellD1.AddComment(null, null, true); // Add comment with no content and no author. The comment is set to be visible.
workBook.SaveAs("addComment.xlsx");
Imports IronXL
Imports System.Linq
Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
Private cellA1 As Cell = workSheet("A1").First()
Private cellD1 As Cell = workSheet("D1").First()
' Add comments
cellA1.AddComment("Hello World!", "John Doe") ' Add comment with content and author. The comment is invisible by default.
cellD1.AddComment(Nothing, Nothing, True) ' Add comment with no content and no author. The comment is set to be visible.
workBook.SaveAs("addComment.xlsx")
編輯註解範例
訪問單元格的 Comment 屬性以檢索單元格的註解對象。這是您可以用來更改作者、內容和可見性的對象。
:path=/static-assets/excel/content-code-examples/how-to/add-comment-edit-comment.cs
using IronXL;
using System.Linq;
WorkBook workBook = WorkBook.Load("addComment.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
Cell cellA1 = workSheet["A1"].First();
// Retrieve comment
var comment = cellA1.Comment;
// Edit comment
comment.Author = "Jane Doe";
comment.Content = "Bye World";
comment.IsVisible = true;
workBook.SaveAs("editComment.xlsx");
Imports IronXL
Imports System.Linq
Private workBook As WorkBook = WorkBook.Load("addComment.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
Private cellA1 As Cell = workSheet("A1").First()
' Retrieve comment
Private comment = cellA1.Comment
' Edit comment
comment.Author = "Jane Doe"
comment.Content = "Bye World"
comment.IsVisible = True
workBook.SaveAs("editComment.xlsx")
移除註解範例
透過首先存取儲存格物件來移除註解。然後,調用儲存格上的 RemoveComment
方法。
:path=/static-assets/excel/content-code-examples/how-to/add-comment-remove-comment.cs
using IronXL;
using System.Linq;
WorkBook workBook = WorkBook.Load("addComment.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;
Cell cellA1 = workSheet["A1"].First();
// Remove comment
cellA1.RemoveComment();
workBook.SaveAs("removeComment.xlsx");
Imports IronXL
Imports System.Linq
Private workBook As WorkBook = WorkBook.Load("addComment.xlsx")
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
Private cellA1 As Cell = workSheet("A1").First()
' Remove comment
cellA1.RemoveComment()
workBook.SaveAs("removeComment.xlsx")