Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
C#
//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];
//Setting the name of the newly added worksheet
worksheet.Name = "Adding Comment in Excel Cell";
//Adding a comment to "F5" cell
int commentIndex = worksheet.Comments.Add("F5");
//Adding a string value to the cell
worksheet.Cells["F5"].PutValue("Hello World");
//Accessing the newly added comment
Comment comment = worksheet.Comments[commentIndex];
//Setting the comment note
comment.Note = "Hello Aspose!";
//Saving the Excel file
workbook.Save("Output-AddingComment.xls");
C#
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
ISheet sheet = hssfworkbook.CreateSheet("Cell comments in POI HSSF");
// Create the drawing patriarch. This is the top‑level container for all shapes, including cell comments.
HSSFPatriarch patr = (HSSFPatriarch)sheet.CreateDrawingPatriarch();
//Create a cell in row 3
ICell cell1 = sheet.CreateRow(3).CreateCell(1);
cell1.SetCellValue(new HSSFRichTextString("Hello, World"));
// Anchor defines the size and position of the comment in the worksheet.
IComment comment1 = patr.CreateCellComment(new HSSFClientAnchor(0, 0, 0, 0, 4, 2, 6, 5));
// Set text in the comment
comment1.String = (new HSSFRichTextString("We can set comments in POI"));
// Set comment author.
// You can see it in the status bar when moving the mouse over the commented cell
comment1.Author = ("Apache Software Foundation");
// The first way to assign a comment to a cell is via the HSSFCell.SetCellComment method
cell1.CellComment = (comment1);
// Write the workbook's stream data to the root directory
FileStream file = new FileStream(@"OutputAddedCommentInCell.xls", FileMode.Create);
hssfworkbook.Write(file);
file.Close();
Download Add Comment in Worksheet from any of the below‑mentioned social coding sites:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.