EPPlus - How to remove a comment from a cell?

3.9k views Asked by At

In EPPlus I can add comments to cell in a worksheet using workSheet.Cells[x, y].AddComment()

But how do I remove a comment from a given cell - there isn't a workSheet.Cells[i, j].RemoveComment() - I need to leave any other comments in place

Thanks in advance for any suggestions

1

There are 1 answers

0
Ernie S On

One would think it would be that simple :).

Check this out:

[TestMethod]
public void Comment_Test()
{
    var existingFile = new FileInfo(@"c:\temp\temp.xlsx");
    if (existingFile.Exists)
        existingFile.Delete();

    using (var package2 = new ExcelPackage(existingFile))
    {
        var ws = package2.Workbook.Worksheets.Add("Sheet1");
        ws.Cells[1, 1].AddComment("Comment Test 1", "Me");
        ws.Cells[1, 2].AddComment("Comment Test 2", "Me");
        ws.Cells[1, 3].AddComment("Comment Test 3", "Me");

        //Alternate way to add a comment
        ws.Comments.Add(ws.Cells[1, 4], "Comment Test 4", "Me");

        //Remove middle comment
        ws.Comments.Remove(ws.Cells[1,2].Comment);

        package2.Save();
    }
}