- NPOI
- Spire.XLS
- Download Sample Code
using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NPOI { class Program { static void Main(string[] args) { //Create workbook IWorkbook workbook = new XSSFWorkbook(); ISheet sheet = workbook.CreateSheet("MySheet"); //Create the drawing patriarch IDrawing drawing = sheet.CreateDrawingPatriarch(); //Create cell and set its value ICell cell = sheet.CreateRow(2).CreateCell(2); cell.SetCellValue("Comment"); //Create comment IClientAnchor anchor = workbook.GetCreationHelper().CreateClientAnchor(); IComment comment = drawing.CreateCellComment(anchor); comment.String = new XSSFRichTextString("Spire.XLS"); comment.Author = ("E-iceblue"); cell.CellComment = (comment); //Save the file FileStream file = File.Create("ExcelComment.xlsx"); workbook.Write(file); file.Close(); //Launch the file System.Diagnostics.Process.Start("ExcelComment.xlsx"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Spire.Xls; namespace Spire.XLS { class Program { static void Main(string[] args) { //Create workbook Workbook workbook = new Workbook(); Worksheet sheet = workbook.CreateEmptySheet("MySheet"); //Set the text of the cell CellRange cell = sheet.Rows[2].Cells[2]; cell.Text = "Comment"; //Add comment ExcelComment comment=cell.AddComment(); comment.Text = "Spire.XLS"; comment.Height = 100; comment.Width = 200; //Save and Launch workbook.SaveToFile("ExcelComment.xlsx", ExcelVersion.Version2013); System.Diagnostics.Process.Start("ExcelComment.xlsx"); } } }