Threaded Comments

This module uses the DevExpress Spreadsheet API to create threaded comments in an Excel document. Threaded comments allow users to have discussions associated with specific cells.

Specify author name and text for the initial comment and the associated response. Select Set Thread as Resolved to mark the comment thread as resolved.

Use the Generate Threaded Comments and Save as... dropdown button to select the output format, generate the document, and download the result.




using DevExpress.Spreadsheet;

Stream GenerateDocumentWithThreadedComments(string threadAuthor, string replyAuthor,
    string firstCommentText, string replyCommentText, bool resolved, DocumentFormat outputFormat) {
    using var workbook = new Workbook();
    var worksheet = workbook.Worksheets.First();

    worksheet.Cells["A1"].Value = "Select the 'B3' cell to read comments";
    worksheet.Cells["A3"].Value = "Discount:";

    var commentCell = worksheet.Cells["B3"];
    commentCell.Value = 0.15;
    commentCell.NumberFormat = "0%";
    worksheet.SelectedCell = commentCell;

    // Add a threaded comment to cell 'B3'
    var comments = worksheet.ThreadedComments;

    ThreadedComment threadedComment = comments.Add(commentCell, threadAuthor, firstCommentText);
    threadedComment.Resolved = resolved;

    // Add a reply
    threadedComment.Reply(replyAuthor, replyCommentText);

    // Prepare output stream
    var outputStream = new MemoryStream();

    // Save the document
    workbook.SaveDocument(outputStream, outputFormat);

    outputStream.Position = 0;
    return outputStream;
}