Inserimento e rimozione di commenti Cell in un foglio di lavoro

Aggiunta e rimozione di commenti su Cells

Per aggiungere commenti alle celle:

  1. Apri un file Excel esistente.
  2. Aggiungi un commento a una cella.
  3. Salva il file.

Per rimuovere i commenti, il processo è simile, con l’eccezione che il commento viene rimosso.

Gli esempi di codice seguenti illustrano innanzitutto comeAggiungi un commento e poi comerimuovere un commento con VSTO o Aspose.Cells for .NET.

Inserimento di commenti

Questi frammenti di codice mostrano come aggiungere prima un commento a una cella conVSTO (C#, VB) e poi conAspose.Cells for .NET (C#, V.B.).

Inserimento di un commento con VSTO

C#

 .......

using Microsoft.VisualStudio.Tools.Applications.Runtime;

using Excel = Microsoft.Office.Interop.Excel;

using Office = Microsoft.Office.Core;

using System.Reflection;

.......

//Instantiate the Application object.

Excel.Application excelApp = new Excel.ApplicationClass();

//Specify the template excel file path.

string myPath=@"d:\test\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();

Inserimento di un commento con Aspose.Cells for .NET

C#

 .......

using Aspose.Cells;

.......

//Specify the template excel file path.

string myPath=@"d:\test\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(@"d:\test\Book1.xls");

Rimozione di commenti

Per rimuovere un commento da una cella, utilizzare le seguenti righe di codice perVSTO (C#, VB) eAspose.Cells for .NET (C#, V.B.).

Rimozione di un commento con VSTO

C#

 //Remove the comment.

rng1.Comment.Delete();    

Rimozione di un commento con Aspose.Cells for .NET

C#

 //Remove the comment.

workbook.Worksheets[0].Comments.RemoveAt("A1");