question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deleting all comments in a workbook ADDs new comments to the workbook

See original GitHub issue

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 (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:open
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rominator1983commented, Dec 7, 2020

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:

  • That the incoming flag are handed over. It would have been wise to add a flag “None” here.
  • That only one flag is handed over to this method. This does in fact collide with the parameterless overload. => This is the reason why I did not include such a change in the PR.
0reactions
Pankratycommented, Jan 17, 2021

sorry for the red builds

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Insert / Delete Comments in Excel (including ...
Right-click anywhere in the selection; Click on Delete Comment (or 'Delete Note' if you're using Office 365). Delete all comments in the selected...
Read more >
Quickly Delete All Comments from Excel
Remove All Comments from a Worksheet. Select all cells in the worksheet. Go to the Home tab > Editing Section on the right...
Read more >
How to delete all comments in a worksheet/workbook?
Or to delete all comments on a page simply pick one cell with a comment, select delete comment, then highlight the whole page...
Read more >
How To Delete All Comments in Excel
Select the worksheet where you want to delete comments, then press F5. · Click Special, select Comments, then click OK. · Open a...
Read more >
How To Delete Comments In Excel (Plus Simple Tips)
Hold the "Shift" key and left-click on comments you want deleted. Next, go through each worksheet section to ensure you identify all comments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found