Вставка и удаление комментариев ячеек в листе в VSTO и Aspose.Cells
Contents
 [
      
        Hide
      ]
    Чтобы добавить комментарии к ячейкам:
- Откройте существующий файл Excel.
- Добавьте комментарий в ячейку.
- Сохраните файл.
Для удаления комментариев процесс аналогичен, за исключением того, что комментарий удаляется.
Приведенные ниже примеры кода показывают, сначала как добавить комментарий, а затем как удалить комментарий с помощью VSTO или Aspose.Cells for .NET.
Вставка комментариев
Эти фрагменты кода показывают, как сначала добавить комментарий к ячейке с помощью VSTO (C#), а затем с помощью Aspose.Cells for .NET (C#).
VSTO
 //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();
Aspose.Cells
 //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 A1 cell.
 int commentIndex = workbook.Worksheets[0].Comments.Add("A1");
//Accessing the newly added comment
 Comment comment = workbook.Worksheets[0].Comments[commentIndex];
//Setting the comment note
 comment.Note = "This is my comment";
//Save As the excel file.
 workbook.Save("Book1.xls");
Удаление комментариев
Чтобы удалить комментарий из ячейки, используйте следующие строки кода для VSTO (C#) и Aspose.Cells for .NET (C#).
VSTO
 //Remove the comment.
  rng1.Comment.Delete();
Aspose.Cells
 //removing comments
 workbook.Worksheets[0].Comments.RemoveAt("A1");