Description
Read and complete the full issue template
Do not randomly delete sections. They are here for a reason.
Do you want to request a feature or report a bug?
- Bug
Did you test against the latest CI build?
- Yes
If you answered No
, please test with the latest development build first.
Version of ClosedXML
current develop (8dcc7c1)
What is the current behavior?
When trying to delete ALL comments of a workbook, closedxml adds comments to all cells that have a value.
This happens with workbooks created by closedxml (as in the unit test below) as well as MS Excel documents that match the criteria.
This BUG probably causes #1570 too. So that one could be checked if it still occurs after the fix.
What is the expected behavior or new feature?
When deleting ALL comments of a workbook there should not be any more comments in the workbook.
Is this a regression from the previous version?
Don't know. I don't think so.
Reproducibility
Code to reproduce problem:
[Test]
public void CanRemoveCommentsWithoutAddingOthers()
{
using (var stream = new MemoryStream())
{
// arange
using (var wb = new XLWorkbook ())
{
var sheet = wb.AddWorksheet("sheet1");
var a1 = sheet.Cell ("A1");
var b5 = sheet.Cell ("B5");
// enabling this will break the test
//a1.SetValue ("test a1");
// enabling this will break the test
//b5.SetValue ("test b5");
a1.Comment.AddText ("no comment");
var cellsWithComments3 = wb.Worksheets.SelectMany (_ => _.CellsUsed (XLCellsUsedOptions.Comments)).ToArray ();
// BUG? When adding the b5.SetValue ("test b5"); this will return 2
Assert.That (cellsWithComments3.Length, Is.EqualTo (1));
wb.SaveAs (stream, true);
}
stream.Position = 0;
using (var wb = new XLWorkbook(stream))
{
var cellsWithComments = wb.Worksheets.SelectMany (_ => _.CellsUsed (XLCellsUsedOptions.Comments)).ToArray ();
Assert.That (cellsWithComments.Length, Is.EqualTo (1));
cellsWithComments.ForEach (_ => _.Clear (XLClearOptions.Comments));
wb.Save ();
}
// assert
stream.Position = 0;
using (var wb = new XLWorkbook(stream))
{
var cellsWithComments = wb.Worksheets.SelectMany (_ => _.CellsUsed (XLCellsUsedOptions.Comments)).ToArray ();
// BUG? when adding a1.SetValue ("test a1"); this will return at least one cell instead of none
Assert.That (cellsWithComments, Is.Empty);
}
}
}