EPPLUS adding comment results error opening excel file
Asked Answered
P

3

8

I would like to add comments at one cell, So.. I did:

... 
ExcelPackage package = new ExcelPackage(new MemoryStream());
var ws = package.WorkBook.WorkSheet[1];
ws.Cells[1, 1].AddComment("Lot Price: $12,000", "");
... 
package.SaveAs(new FileInfo("fileout.xlsx"));
package.Dispose();

When try open the resulted "fileout.xlsx", it showed a dialog box saying to recover as much as possible... Then the recovered fileout.xlsx displays errors:

"Removed Part: /xl/comments1.xml part with XML error. (Comments) Load error. Line 5, column 0. Removed Part: /xl/comments5.xml part with XML error. (Comments) Load error. Line 5, column 24."

It appears that EPPlus produced a wrong format xml when there are comments. I would like to share my solutions for this problem:

I just added a NON-BLANK header line for the comments, such as "REF" here:

ws.Cells[1, 1].AddComment("Lot Price: $12,000", "REF");

I hope someone might be helped by this.

Phyllis answered 26/1, 2017 at 22:55 Comment(1)
Thank you, this has helped me too. You should post your solution as an answer and accept that, if you can.Dorelle
P
7

Some one suggested to post it as answer. Here it is:

The problem disappears if like this: I just added a NON-BLANK header line for the comments, such as "REF" here:

ws.Cells[1, 1].AddComment("Lot Price: $12,000", "REF");

I hope someone might be helped by this.

Phyllis answered 29/7, 2017 at 21:18 Comment(0)
B
0

I see the same problem.for my instance,I use function AddComent with empty value in second parameter. at first ,my code like this:

ExcelRange range = newsheet.SelectedRange[1, 1];
newExcel.SetBGColor(range, Color.Red);
range.AddComment("no data", "");

then I change the last code like this:

range.AddComment("no data", "some body");

It works

Birthday answered 24/6, 2020 at 5:6 Comment(0)
G
0

You can add a space " " it works too.

Glenn answered 27/9, 2023 at 10:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.