How to add comment to a specific cell?

Hi,

How to add comment to a specific cell on an excel sheet? I only have cell object available in the current context.

Also, how to make a cell invisible?

PS: I saw a example where we can add comment using worksheet object to the cell. Something like

Comments comments = workbook.Worksheets[0].Comments;

I don't want to use above model and want to add comment directly to the cell object which I aquired from a sheet object. Is it possible?

Regards, Vinay

Hi,

Well, you need to use this model to add comments to the worksheet cells. You will use Comments.Add() method, this method would take cell object / indices as its argument, so you can add comment to a specific cell in the worksheet.

See the following sample code for your reference:

/Instantiating a Workbook object

Workbook workbook = new Workbook();



//Adding a new worksheet to the Workbook object


int sheetIndex = workbook.Worksheets.Add();



//Obtaining the reference of the newly added worksheet by passing its sheet index


Worksheet worksheet = workbook.Worksheets[sheetIndex];



//Adding a comment to “F5” cell


int commentIndex = worksheet.Comments.Add(“F5”);



//Accessing the newly added comment


Comment comment = worksheet.Comments[commentIndex];



//Setting the comment note


comment.Note = “Hello Aspose!”;



//Saving the Excel file


workbook.Save(“C:\book1.xls”, FileFormatType.Default);


For further reference, see the following document:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/adding-comments.html

For hiding a specific cell, you need to hide the related row/column for the cell. See the document for reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/hidingunhiding-rows-and-columns.html


Thank you.