Hello! I have code snippet (Aspose.Cells 19.10) for create workbook and several threaded comments.
After import to OneDrive and open in Office365 Excel I got comments order randomized:
image.png (35.2 KB)
Please help with this problem, I want to save comments order.
Snippet (Java)
import com.aspose.cells.*;
public class AsposeThreadCommentsOrderMain {
public static void main(String[] args) throws Exception {
License license = new License();
license.setLicense("aspose.lic");
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
int author1Index = workbook.getWorksheets().getThreadedCommentAuthors()
.add("Author 1", "author1", "OV");
int author2Index = workbook.getWorksheets().getThreadedCommentAuthors()
.add("Author 2", "author2", "OV");
ThreadedCommentAuthor author1 = workbook.getWorksheets().getThreadedCommentAuthors().get(author1Index);
ThreadedCommentAuthor author2 = workbook.getWorksheets().getThreadedCommentAuthors().get(author2Index);
addThreadedComment(worksheet, "C2", "1", author1);
addThreadedComment(worksheet, "C2", "2", author1);
addThreadedComment(worksheet, "C2", "3", author1);
addThreadedComment(worksheet, "C2", "4", author2);
addThreadedComment(worksheet, "C2", "5", author1);
addThreadedComment(worksheet, "C2", "6", author1);
addThreadedComment(worksheet, "C2", "7", author1);
addThreadedComment(worksheet, "C2", "8", author1);
addThreadedComment(worksheet, "C2", "9", author1);
addThreadedComment(worksheet, "C2", "10", author2);
addThreadedComment(worksheet, "C2", "11", author1);
addThreadedComment(worksheet, "C2", "12", author2);
workbook.save("output.xlsx");
}
private static void addThreadedComment(Worksheet worksheet, String cellName, String text, ThreadedCommentAuthor author) {
Cell cell = worksheet.getCells().get(cellName);
CommentCollection commentCollection = cell.getWorksheet().getComments();
Comment comment = commentCollection.get(cell.getRow(), cell.getColumn());
if (comment == null) {
int commentIdx = commentCollection.add(cell.getRow(), cell.getColumn());
comment = commentCollection.get(commentIdx);
}
comment.getThreadedComments().add(text, author);
}
}