Wie man einen Kommentar hinzufügt
In Excel ist ein Kommentar eine Notiz oder Anmerkung, die einer Zelle hinzugefügt werden kann, um zusätzliche Informationen bereitzustellen, ohne den eigentlichen Inhalt der Zelle zu beeinflussen. Kommentare sind nützlich, um Erklärungen, Kontext oder Erinnerungen zu den Daten oder Berechnungen in einer bestimmten Zelle bereitzustellen.
Wie man einen Kommentar hinzufügt
- Laden Sie die C#-Bibliothek herunter, um die Kommentarfunktionalität zu aktivieren
- Öffnen Sie eine vorhandene oder erstellen Sie eine neue Excel-Tabelle
- Verwenden Sie die
AddComment
-Methode, um Kommentare hinzuzufügen - Rufen Sie Kommentare ab und bearbeiten Sie sie, indem Sie auf die Comment-Eigenschaft zugreifen
- Kommentare aus Zellen mit der
RemoveComment
-Methode entfernen
Legen Sie los mit IronXL
Beginnen Sie noch heute mit der Verwendung von IronXL in Ihrem Projekt mit einer kostenlosen Testversion.
Kommentar hinzufügen Beispiel
Wählen Sie die Zelle aus und verwenden Sie die Methode AddComment
, um der Zelle einen Kommentar hinzuzufügen. In der Standardeinstellung ist der Kommentar unsichtbar. Bewegen Sie den Mauszeiger über die Zelle, um den unsichtbaren Kommentar zu sehen.
: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")
Kommentar bearbeiten Beispiel
Greifen Sie auf die Kommentar-Eigenschaft der Zelle zu, um das Kommentarobjekt für die Zelle abzurufen. Dies ist das Objekt, mit dem Sie den Autor, den Inhalt und die Sichtbarkeit ändern können.
: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")
Kommentar entfernen Beispiel
Entfernen Sie einen Kommentar aus einer Zelle, indem Sie zunächst auf das Zellenobjekt zugreifen. Rufen Sie dann die RemoveComment
-Methode auf der Zelle auf.
: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")