Deleting all comments in a workbook ADDs new comments to the workbook
See original GitHub issueRead 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 (8dcc7c10f276c59baab8b2ecba5dfb515262d9cf)
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 https://github.com/ClosedXML/ClosedXML/issues/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);
}
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
For the case of “B5” in my test: it looks like in XLCells.GetUsedCellsInRange the cellRange includes B5. This does not seem correct as those should be filtered according to the _options. The reason for that is, that the method XLCell.IsEmpty (which is public and contained in interface IXLCell) returns false when there any content in the cell completely ignoring the parameter XLCellsUsedOptions options. I think it should only do so when the option XLCellsUsedOptions.Contents is handed over. => I will address this issue in a PR shortly.
Furthermore the method also ignores the fact that XLCellsUsedOptions is a Flags enum. Which now has to be resolved by a caller using this method directly.
I do think it would have been a good idea to check two things:
No problem at all! We usually mark the unfinished work with
WIP
prefix in a PR’s name and then this bot takes care of preventing it from merging.Thanks for your contribution! We both with @igitur have been quite busy lately and not able to react timely but we really appreciate any help we are getting!