|
Product |
ExcelWriter |
Version |
all versions |
Title |
Cell comments appear in the wrong cell and you get a "Data may have been lost" error |
Problem |
You are creating a worksheet with ExcelApplication, and are adding several comments to cells programmatically. When the file is opened, you get an error saying that data may have been lost. Additionally, some of the comments appear in the wrong cell. |
Solution |
This issue is a known problem, and will be investigated by our development team. The error can occur if you access a comment directly through the Cell.Comment property. For example, you may get the error if you have the following:
[C#]
|
[VB.NET]
|
|
ws.Cells[row,col].Comment.Text = "this is a comment";
ws.Cells(row,col).Comment.Text = "this is a comment"
|
The solution is to use the Worksheet.Comments.CreateComment method to create a Comment object, and then manipulate that object directly. For example, you could have:
[C#]
|
[VB.NET]
|
|
Comment myComment = ws.Comments.CreateComment(row,col);
myComment.Text = "This is a comment";
Dim myComment As Comment = ws.Comments.CreateComment(row,col)
myComment.Text = "This is a comment"
|
The CreateComment method is described in detail in the documentation for the Comments collection, which can be accessed through the Comments property of the Worksheet class. Once you have created the Comment object with the factory method, you should continue to refer to this object, and not try to access it through the Cell object. For example:
[C#]
|
[VB.NET]
|
|
//This is the right way to refer to the comment you just created:
myComment.FitToText = true;
//You should NOT do this:
//myCell.Comment.FitToText = true;
'This is the right way to refer to the comment you just created:
myComment.FitToText = True
'You should NOT do this:
'myCell.Comment.FitToText = True
|
For a description of the properties that you can set for the Comment class, you can refer to the documentation for that class. If you use the factory method to create the comment and do not refer to the Cell.Comment property, the error will be eliminated. |
Created : 2/2/2009 4:18:52 PM (last modified : 4/23/2012 4:35:59 PM) |
|