Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EPPLUS adding comment results error opening excel file

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.

like image 812
Pan Avatar asked Jan 26 '17 22:01

Pan


1 Answers

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.

like image 171
Pan Avatar answered Oct 20 '22 00:10

Pan