如何添加評論

This article was translated from English: Does it need improvement?
Translated
View the article in English

查克尼思·賓

在 Excel 中,註解是一種可以添加到儲存格的備註或注釋,以提供額外的資訊而不影響儲存格的實際內容。註解對於提供數據或計算的解釋、上下文或提醒非常有用。


C# NuGet 程式庫用于 Excel

安裝與 NuGet

Install-Package IronXL.Excel
Java PDF JAR

下載 DLL

下載DLL

手動安裝到您的項目中

C# NuGet 程式庫用于 Excel

安裝與 NuGet

Install-Package IronXL.Excel
Java PDF JAR

下載 DLL

下載DLL

手動安裝到您的項目中

立即開始在您的專案中使用IronPDF,並享受免費試用。

第一步:
green arrow pointer

查看 IronXLNuget 快速安裝和部署。已被下載超過800萬次,它正用C#改變Excel。

C# NuGet 程式庫用于 Excel nuget.org/packages/IronXL.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")
VB   C#

編輯註解範例

訪問單元格的 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")
VB   C#

移除註解範例

透過首先存取儲存格物件來移除註解。然後,調用儲存格上的 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")
VB   C#

查克尼思·賓

軟體工程師

Chaknith 是開發者界的夏洛克福爾摩斯。他第一次意識到自己可能有個軟體工程的未來,是在他為了娛樂而參加程式挑戰的時候。他的重點是 IronXL 和 IronBarcode,但他也引以為豪的是,他幫助客戶解決所有產品的問題。Chaknith 利用他與客戶直接對話中獲得的知識,以進一步改進產品。他的實際反饋超越了 Jira 工單,並支持產品開發、文件撰寫和行銷,以提升客戶的整體體驗。不在公司時,他通常在學習機器學習、寫程式和徒步旅行。