Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ooxml/XSSF/Streaming/SXSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,15 @@ public ICell CopyCellTo(int targetIndex)

public void RemoveCellComment()
{
IComment comment = this.CellComment;
if (comment != null)
{
CellAddress ref1 = new CellAddress(RowIndex, ColumnIndex);
XSSFSheet sh = ((SXSSFSheet)Sheet)._sh;
sh.GetCommentsTable(false).RemoveComment(ref1);
sh.GetVMLDrawing(false).RemoveCommentShape(RowIndex, ColumnIndex);
}

RemoveProperty(Property.COMMENT);
}

Expand Down
103 changes: 103 additions & 0 deletions testcases/ooxml/XSSF/UserModel/TestXSSFComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,109 @@ public void Bug57838DeleteRowsWthCommentsBug()
wb.Close();
}

[Test]
public void TestRemoveXSSFCellComment()
{
IWorkbook wb = new XSSFWorkbook();
try
{
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(1);
ICell cell = row.CreateCell(0);
cell.SetCellValue("test");

IDrawing drawing = sheet.CreateDrawingPatriarch();
ICreationHelper factory = wb.GetCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
IClientAnchor anchor = factory.CreateClientAnchor();
anchor.Col1 = cell.ColumnIndex;
anchor.Col2 = cell.ColumnIndex + 1;
anchor.Row1 = row.RowNum;
anchor.Row2 = row.RowNum + 3;
// Create the comment and set the text+author
IComment comment = drawing.CreateCellComment(anchor);
IRichTextString str = factory.CreateRichTextString("Hello, World!");
comment.String = str;
comment.Author = "Apache POI";

cell.CellComment = comment;

var exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));

cell.RemoveCellComment();
exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNull(exCellComment);

IComment newComment = drawing.CreateCellComment(anchor);
newComment.String = str;
newComment.Author = "Apache POI";
cell.CellComment = newComment;

exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.NotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));
}
finally
{
wb.Close();
}
}

[Test]
public void TestRemoveSXSSFCellComment()
{
IWorkbook wb = new SXSSFWorkbook();
try
{
ISheet sheet = wb.CreateSheet();
IRow row = sheet.CreateRow(1);
ICell cell = row.CreateCell(0);
cell.SetCellValue("test");

IDrawing drawing = sheet.CreateDrawingPatriarch();
ICreationHelper factory = wb.GetCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
IClientAnchor anchor = factory.CreateClientAnchor();
anchor.Col1 = cell.ColumnIndex;
anchor.Col2 = cell.ColumnIndex + 1;
anchor.Row1 = row.RowNum;
anchor.Row2 = row.RowNum + 3;
// Create the comment and set the text+author
IComment comment = drawing.CreateCellComment(anchor);
IRichTextString str = factory.CreateRichTextString("Hello, World!");
comment.String = str;
comment.Author = "Apache POI";

cell.CellComment = comment;

var exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));

cell.RemoveCellComment();
exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.IsNull(exCellComment);

IComment newComment = drawing.CreateCellComment(anchor);
newComment.String = str;
newComment.Author = "Apache POI";
cell.CellComment = newComment;

exCellComment = sheet.GetCellComment(new CellAddress(1, 0));
Assert.NotNull(exCellComment);
Assert.IsTrue(exCellComment.String.String.Equals("Hello, World!"));
Assert.IsTrue(exCellComment.Author.Equals("Apache POI"));
}
finally
{
wb.Close();
}
}
}

}