I created a sample excel file in Office 365 and added some Threaded Comments to a cell. Then I use the Cells.Find method for searching text in the document. For example “This is the first reply” string. In this case, the function returns the correct cell with the comment which contains the searched text.
But after I edit the comment in MS Office Excel 2016 which not supports this Threaded Comments feature the Cells.Find did not find anything however if I reupload the edited file to Office 365 the threaded comment is showing up with the “This is the first reply” text.
I extracted the edited xlsx file with 7-zip and I noticed that there is two comments related XML file and its content is different.
- comments1.xml contains the edited comment
- threadedComment1.xml contains the original comment
Do you have any solution for this edge case? How can I find text (with Cells.Find method) in the threaded comments if the old comments (Note) are modified?
Aspose.PDF .NET 20.2 version
sample-files.zip (16.2 KB)
Code snippet:
private void SearchInCells(Cells cells, string searchTerm)
{
CellArea ca = new CellArea {
StartRow = cells.MinDataRow,
StartColumn = cells.MinDataColumn,
EndRow = cells.MaxDataRow,
EndColumn = cells.MaxDataColumn,
};
FindOptions findOptions = new FindOptions();
findOptions.SetRange(ca);
findOptions.RegexKey = true;
findOptions.CaseSensitive = false;
findOptions.SearchBackward = true;
findOptions.LookInType = LookInType.Comments;
Cell nextCell = cells.Find(searchTerm, null, findOptions);
while (nextCell != null)
{
Console.WriteLine($"{nextCell.Name}:");
Console.WriteLine($"Note: {nextCell.Worksheet.Comments[nextCell.Row, nextCell.Column].Note}");
ThreadedCommentCollection threadedComments = nextCell.Worksheet.Comments.GetThreadedComments(nextCell.Row, nextCell.Column);
foreach (var threadedComment in threadedComments)
{
Console.WriteLine($"{nextCell.Name}:");
Console.WriteLine($"Threaded Comment Author: {threadedComment.Author.Name}");
Console.WriteLine($"Threaded Comments: {threadedComment.Notes}");
}
nextCell = cells.Find(searchTerm, nextCell, findOptions);
}
}
Thanks,
Gabor