1
Vote

Deleting a comment corrupts the file

description

Deleting a comment causes excel 2007 to choke on the file.

Here is a repro case:
    [Test]
    [Ignore("Run interactively as this spawns excel")]
    public void TestCommentDelete()
    {

        var path = new FileInfo("test.xlsx");
        // scope 1: write with a comment
        {
            var pack = new ExcelPackage();
            var sheet = pack.Workbook.Worksheets.Add("test");
            var cell = sheet.Cells[1, 1];
            cell.Value = "hi";
            cell.AddComment("hello world", "me");
            pack.SaveAs(path);
        }

        // scope 2: read and remove the comment
        {
            var pack = new ExcelPackage(path);
            var sheet = pack.Workbook.Worksheets["test"];
            var cell = sheet.Cells[1, 1];
            var comment = cell.Comment;
            sheet.Comments.Remove(comment);
            pack.Save();
        }

        // scope 3: read and make sure well formed
        {
            var pack = new ExcelPackage(path);
            var sheet = pack.Workbook.Worksheets["test"];
            var cell = sheet.Cells[1, 1];
            var comment = cell.Comment;
            Assert.IsNull(comment);

            // now run excel - it will choke on it
            Process.Start(new ProcessStartInfo(path.FullName));
        }

And here is the recovery report from Excel 2007

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">error133480_02.xmlErrors were detected in file 'D:\svn\main\trunk\Shared\Tests\bin\Debug\test.xlsx'</summary><removedParts summary="Following is a list of removed parts:"><removedPart>Removed Part: Drawing shape.</removedPart></removedParts></recoveryLog>

file attachments

comments

FlorianDoyon wrote Jun 7, 2012 at 1:41 PM

uploaded the corrupted file

JanKallman wrote Jun 13, 2012 at 8:02 PM

This should be fixed in the latest source. Try it and let me know how it goes.

FlorianDoyon wrote Jun 15, 2012 at 12:14 PM

Hi Jan,

I reproduced the issue with epplus-b223261ec744 which is the latest version as of June 15th.

Regards,
Florian