7

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.

LA.27
  • 1,888
  • 19
  • 35
Pan
  • 131
  • 2
  • 6

2 Answers2

6

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.

Pan
  • 131
  • 2
  • 6
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

Xin
  • 69
  • 4