Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To add comments to cells:
To remove the comments, the process is similar, with the exception that the comment is removed.
The code samples below illustrate how to add a comment and then how to remove a comment with either VSTO or Aspose.Cells for .NET.
These code snippets show how to add a comment to a cell, first with VSTO (C#), and then with Aspose.Cells for .NET (C#).
//Instantiate the Application object.
Excel.Application excelApp = Application;
//Specify the template Excel file path.
string myPath = "Book1.xls";
//Open the Excel file.
excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
//Get the A1 cell.
Excel.Range rng1 = excelApp.get_Range("A1", Missing.Value);
//Add the comment with text.
rng1.AddComment("This is my comment");
//Save the file.
excelApp.ActiveWorkbook.Save();
//Quit the Application.
excelApp.Quit();
//Specify the template Excel file path.
string myPath = "Book1.xls";
//Instantiate a new Workbook.
//Open the Excel file.
Workbook workbook = new Workbook(myPath);
//Add a comment to the A1 cell.
int commentIndex = workbook.Worksheets[0].Comments.Add("A1");
//Access the newly added comment.
Comment comment = workbook.Worksheets[0].Comments[commentIndex];
//Set the comment note.
comment.Note = "This is my comment";
//Save the Excel file.
workbook.Save("Book1.xls");
To remove a comment from a cell, use the following lines of code for VSTO (C#) and Aspose.Cells for .NET (C#).
//Remove the comment.
rng1.Comment.Delete();
// Removing comments
workbook.Worksheets[0].Comments.RemoveAt("A1");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.