From 94835fc7b6c5fedc2570988bf5df1ac4aecc2dc0 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:07:21 +0500 Subject: [PATCH 01/25] Add example: create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john --- comments-and-notes/agents.md | 57 +++++++++++++++++++ ...ded-comment-to-cell-a1-with-author-john.cs | 21 +++++++ 2 files changed, 78 insertions(+) create mode 100644 comments-and-notes/agents.md create mode 100644 comments-and-notes/create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md new file mode 100644 index 000000000..b32d7a30c --- /dev/null +++ b/comments-and-notes/agents.md @@ -0,0 +1,57 @@ +# Comments and Notes Examples + +This folder contains **Aspose.Cells for .NET** code examples related to: + +Comments and Notes + + +## Purpose + +These examples demonstrate common **Aspose.Cells APIs** used when working with: + +- Workbooks +- Worksheets +- Cells +- Formulas +- Charts +- Data operations + + +## Example Files + +Each `.cs` file demonstrates a specific task related to **Comments and Notes**. + +Example: + +create-a-workbook.cs + + +## Required Namespaces + +Most examples will require: + +using Aspose.Cells; + + +## Common Pattern + +Typical Aspose.Cells workflow: + +Workbook workbook = new Workbook(); + +Worksheet sheet = workbook.Worksheets[0]; + +Cells cells = sheet.Cells; + + +## Output + +Examples may generate: + +- XLSX files +- PDF files +- CSV files +- Images + +Output files are written to the working directory. +- create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs diff --git a/comments-and-notes/create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs b/comments-and-notes/create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs new file mode 100644 index 000000000..f42962561 --- /dev/null +++ b/comments-and-notes/create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs @@ -0,0 +1,21 @@ +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a threaded comment author named John + int authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add("John", "john@example.com", "PROVIDER"); + ThreadedCommentAuthor johnAuthor = workbook.Worksheets.ThreadedCommentAuthors[authorIndex]; + + // Add a threaded comment to cell A1 using the author + worksheet.Comments.AddThreadedComment("A1", "This is a threaded comment.", johnAuthor); + + // Save the workbook + workbook.Save("ThreadedCommentJohn.xlsx"); + } +} \ No newline at end of file From 777891f85790a5a9135569cf02891e22dae66749 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:08:05 +0500 Subject: [PATCH 02/25] Add example: load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors --- comments-and-notes/agents.md | 1 + ...ts-from-column-b-and-list-their-authors.cs | 40 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 46 insertions(+) create mode 100644 comments-and-notes/load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index b32d7a30c..a314b12a4 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -55,3 +55,4 @@ Examples may generate: Output files are written to the working directory. - create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs +- load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs diff --git a/comments-and-notes/load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs b/comments-and-notes/load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs new file mode 100644 index 000000000..48ef2a637 --- /dev/null +++ b/comments-and-notes/load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs @@ -0,0 +1,40 @@ +using System; +using Aspose.Cells; + +class Program +{ + static void Main() + { + // Load the existing workbook + Workbook workbook = new Workbook("input.xlsx"); + + // Access the first worksheet (adjust index if needed) + Worksheet worksheet = workbook.Worksheets[0]; + + // Get the comments collection of the worksheet + CommentCollection comments = worksheet.Comments; + + // Determine the last used row in the worksheet to limit the loop + int lastRow = worksheet.Cells.MaxDataRow; + + // Column B has index 1 (zero‑based) + int columnBIndex = 1; + + // Iterate through each row that may contain a threaded comment in column B + for (int row = 0; row <= lastRow; row++) + { + // Retrieve threaded comments for the cell at (row, column B) + ThreadedCommentCollection threadedComments = comments.GetThreadedComments(row, columnBIndex); + + // If there are any threaded comments, list their authors + if (threadedComments != null && threadedComments.Count > 0) + { + foreach (ThreadedComment tc in threadedComments) + { + // Output the author name of each threaded comment + Console.WriteLine($"Cell B{row + 1}: Author = {tc.Author.Name}"); + } + } + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index fa283587c..58b05f280 100644 --- a/index.json +++ b/index.json @@ -9,6 +9,11 @@ "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs", "title": "Create a new workbook and add a threaded comment to cell A1 with author John." }, + { + "category": "comments-and-notes", + "file": "load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs", + "title": "Load an existing workbook, retrieve all threaded comments from column B, and list their authors." + }, { "category": "timeline", "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", From a28080204babcb55dfb7fd9de0cb6f7bb0307487 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:08:41 +0500 Subject: [PATCH 03/25] Add example: iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp --- comments-and-notes/agents.md | 1 + ...ents-text-author-and-creation-timestamp.cs | 43 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 49 insertions(+) create mode 100644 comments-and-notes/iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index a314b12a4..39349cc64 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -56,3 +56,4 @@ Examples may generate: Output files are written to the working directory. - create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs - load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs +- iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs diff --git a/comments-and-notes/iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs b/comments-and-notes/iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs new file mode 100644 index 000000000..f8050c10b --- /dev/null +++ b/comments-and-notes/iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs @@ -0,0 +1,43 @@ +using System; +using Aspose.Cells; + +class ThreadedCommentIterationDemo +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a threaded comment author to the workbook + int authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add( + "Alice", // Author name + "alice@example.com", // User ID / email + "Provider1"); // Provider ID + ThreadedCommentAuthor author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex]; + + // Add a regular comment to cell A1 (required to host threaded comments) + int commentIndex = worksheet.Comments.Add("A1"); + Comment comment = worksheet.Comments[commentIndex]; + + // Add threaded comments to the comment + comment.ThreadedComments.Add("First threaded comment", author); + comment.ThreadedComments.Add("Second threaded comment", author); + + // Retrieve the collection of threaded comments + ThreadedCommentCollection threadedComments = comment.ThreadedComments; + + // Iterate through the collection and display each comment's details + for (int i = 0; i < threadedComments.Count; i++) + { + ThreadedComment tc = threadedComments[i]; + Console.WriteLine($"Comment {i + 1}:"); + Console.WriteLine($" Text : {tc.Notes}"); + Console.WriteLine($" Author : {tc.Author.Name}"); + Console.WriteLine($" Created: {tc.CreatedTime}"); + } + + // Save the workbook (optional, demonstrates lifecycle usage) + workbook.Save("ThreadedCommentsDemo.xlsx"); + } +} \ No newline at end of file diff --git a/index.json b/index.json index 58b05f280..501257a96 100644 --- a/index.json +++ b/index.json @@ -9,6 +9,11 @@ "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs", "title": "Create a new workbook and add a threaded comment to cell A1 with author John." }, + { + "category": "comments-and-notes", + "file": "iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs", + "title": "Iterate through a ThreadedCommentCollection to display each comment's text, author, and creation timestamp." + }, { "category": "comments-and-notes", "file": "load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs", From e9418567c722a2efa478d84dd2bc21558f571f3d Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:09:38 +0500 Subject: [PATCH 04/25] Add example: edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value --- comments-and-notes/agents.md | 1 + ...its-text-property-to-a-new-string-value.cs | 53 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 59 insertions(+) create mode 100644 comments-and-notes/edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 39349cc64..9df702fac 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -57,3 +57,4 @@ Output files are written to the working directory. - create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs - load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs - iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs +- edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs diff --git a/comments-and-notes/edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs b/comments-and-notes/edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs new file mode 100644 index 000000000..36012875c --- /dev/null +++ b/comments-and-notes/edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using Aspose.Cells; + +class EditThreadedComment +{ + static void Main() + { + try + { + const string inputPath = "input.xlsx"; + const string outputPath = "output.xlsx"; + + // Verify that the input workbook exists + if (!File.Exists(inputPath)) + { + Console.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the workbook + Workbook workbook = new Workbook(inputPath); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Cell that contains the threaded comment to edit + string targetCell = "A1"; + + // Retrieve threaded comments for the cell (may be null if none exist) + ThreadedCommentCollection threadedComments = worksheet.Comments.GetThreadedComments(targetCell); + + if (threadedComments != null && threadedComments.Count > 0) + { + // Edit the first threaded comment + ThreadedComment comment = threadedComments[0]; + comment.Notes = "Updated comment text set via Aspose.Cells."; + } + else + { + Console.WriteLine($"No threaded comments found at cell {targetCell}."); + } + + // Save the updated workbook + workbook.Save(outputPath); + Console.WriteLine($"Workbook saved to {outputPath}"); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 501257a96..cf5928f94 100644 --- a/index.json +++ b/index.json @@ -9,6 +9,11 @@ "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs", "title": "Create a new workbook and add a threaded comment to cell A1 with author John." }, + { + "category": "comments-and-notes", + "file": "edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs", + "title": "Edit a specific threaded comment by setting its Text property to a new string value." + }, { "category": "comments-and-notes", "file": "iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs", From acb5ce480eabf93bf3c71b25c1c47eaf72875955 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:10:11 +0500 Subject: [PATCH 05/25] Add example: remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object --- comments-and-notes/agents.md | 1 + ...the-remove-method-on-the-comment-object.cs | 28 +++++++++++++++++++ index.json | 5 ++++ 3 files changed, 34 insertions(+) create mode 100644 comments-and-notes/remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 9df702fac..f8401205f 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -58,3 +58,4 @@ Output files are written to the working directory. - load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs - iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs - edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs +- remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs diff --git a/comments-and-notes/remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs b/comments-and-notes/remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs new file mode 100644 index 000000000..44843410e --- /dev/null +++ b/comments-and-notes/remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs @@ -0,0 +1,28 @@ +using System; +using Aspose.Cells; + +class RemoveThreadedCommentDemo +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a threaded comment author + int authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add( + "John Doe", // author name + "john.doe@example.com", // author email / user id + "PROVIDER"); // provider id + ThreadedCommentAuthor author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex]; + + // Add a threaded comment to cell C3 + worksheet.Comments.AddThreadedComment("C3", "Initial threaded comment", author); + + // Remove the comment (and its threaded comments) from cell C3 + worksheet.Comments.RemoveAt("C3"); + + // Save the workbook + workbook.Save("RemovedThreadedComment.xlsx"); + } +} \ No newline at end of file diff --git a/index.json b/index.json index cf5928f94..697f361ad 100644 --- a/index.json +++ b/index.json @@ -24,6 +24,11 @@ "file": "load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs", "title": "Load an existing workbook, retrieve all threaded comments from column B, and list their authors." }, + { + "category": "comments-and-notes", + "file": "remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs", + "title": "Remove a threaded comment from cell C3 using the Remove method on the comment object." + }, { "category": "timeline", "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", From 88c9a8e9dff594a215c2adc3be387fdcc82d9c5d Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:11:23 +0500 Subject: [PATCH 06/25] Add example: set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support --- comments-and-notes/agents.md | 1 + ...left-for-bidirectional-language-support.cs | 27 +++++++++++++++++++ index.json | 5 ++++ 3 files changed, 33 insertions(+) create mode 100644 comments-and-notes/set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index f8401205f..8d1e28fce 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -59,3 +59,4 @@ Output files are written to the working directory. - iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs - edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs - remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs +- set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs diff --git a/comments-and-notes/set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs b/comments-and-notes/set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs new file mode 100644 index 000000000..14498b15d --- /dev/null +++ b/comments-and-notes/set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs @@ -0,0 +1,27 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +class SetCommentShapeTextDirection +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a comment to cell A1 + int commentIndex = worksheet.Comments.Add("A1"); + Comment comment = worksheet.Comments[commentIndex]; + comment.Note = "مثال على النص من اليمين إلى اليسار"; // Sample Arabic text + + // Access the shape associated with the comment + CommentShape commentShape = comment.CommentShape; + + // Set the text direction of the comment's shape to RightToLeft + commentShape.TextDirection = TextDirectionType.RightToLeft; + + // Save the workbook + workbook.Save("CommentShapeRightToLeft.xlsx"); + } +} \ No newline at end of file diff --git a/index.json b/index.json index 697f361ad..d668a5ecc 100644 --- a/index.json +++ b/index.json @@ -29,6 +29,11 @@ "file": "remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs", "title": "Remove a threaded comment from cell C3 using the Remove method on the comment object." }, + { + "category": "comments-and-notes", + "file": "set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs", + "title": "Set the text direction of a comment's shape to RightToLeft for bidirectional language support." + }, { "category": "timeline", "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", From c6ae8522099e7fb0d3463f5f91a64b5074e970f5 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:11:56 +0500 Subject: [PATCH 07/25] Add example: set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout --- comments-and-notes/agents.md | 1 + ...tobottom-for-vertical-annotation-layout.cs | 26 +++++++++++++++++++ index.json | 5 ++++ 3 files changed, 32 insertions(+) create mode 100644 comments-and-notes/set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 8d1e28fce..d8b9856c4 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -60,3 +60,4 @@ Output files are written to the working directory. - edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs - remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs - set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs +- set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs diff --git a/comments-and-notes/set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs b/comments-and-notes/set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs new file mode 100644 index 000000000..b830f43fd --- /dev/null +++ b/comments-and-notes/set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs @@ -0,0 +1,26 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsCommentOrientation +{ + class Program + { + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a comment to cell A1 + int commentIndex = worksheet.Comments.Add("A1"); + Comment comment = worksheet.Comments[commentIndex]; + comment.Note = "This comment will be displayed vertically."; + + // Set the text direction of the comment's shape to TopToBottom + comment.TextOrientationType = TextOrientationType.TopToBottom; + + // Save the workbook + workbook.Save("CommentTopToBottom.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index d668a5ecc..82570a1f3 100644 --- a/index.json +++ b/index.json @@ -34,6 +34,11 @@ "file": "set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs", "title": "Set the text direction of a comment's shape to RightToLeft for bidirectional language support." }, + { + "category": "comments-and-notes", + "file": "set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs", + "title": "Set the text direction of a comment's shape to TopToBottom for vertical annotation layout." + }, { "category": "timeline", "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", From b5161bbe3bf9176f4980d95524f542e820a5b4b9 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:12:30 +0500 Subject: [PATCH 08/25] Add example: change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor --- comments-and-notes/agents.md | 1 + ...g-a-red-value-to-shapetextbodyfontcolor.cs | 36 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 42 insertions(+) create mode 100644 comments-and-notes/change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index d8b9856c4..09205ae19 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -61,3 +61,4 @@ Output files are written to the working directory. - remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs - set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs - set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs +- change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs diff --git a/comments-and-notes/change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs b/comments-and-notes/change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs new file mode 100644 index 000000000..45ac86953 --- /dev/null +++ b/comments-and-notes/change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs @@ -0,0 +1,36 @@ +using System; +using System.Drawing; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +namespace AsposeCellsCommentFontColor +{ + class Program + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a comment to cell A1 + int commentIndex = worksheet.Comments.Add("A1"); + Comment comment = worksheet.Comments[commentIndex]; + comment.Note = "This is a sample comment"; + + // Access the shape attached to the comment + CommentShape commentShape = comment.CommentShape; + + // Ensure the shape has a TextBody collection + // Set the font color of the first text run to red + // (FontSettingCollection items expose a Font property) + commentShape.TextBody[0].Font.Color = Color.Red; + + // Optionally make the comment visible + comment.IsVisible = true; + + // Save the workbook + workbook.Save("CommentWithRedFont.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 82570a1f3..18600329b 100644 --- a/index.json +++ b/index.json @@ -4,6 +4,11 @@ "language": "csharp", "framework": ".NET", "examples": [ + { + "category": "comments-and-notes", + "file": "change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs", + "title": "Change the font color of a comment by assigning a red value to Shape.TextBody.Font.Color." + }, { "category": "comments-and-notes", "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs", From 7f257b53c17f536bed743e91f25f04b6c87cc515 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:13:15 +0500 Subject: [PATCH 09/25] Add example: update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor --- comments-and-notes/agents.md | 1 + ...e-to-green-using-shapetextbodyfontcolor.cs | 60 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 66 insertions(+) create mode 100644 comments-and-notes/update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 09205ae19..b32064024 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -62,3 +62,4 @@ Output files are written to the working directory. - set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs - set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs - change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs +- update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs diff --git a/comments-and-notes/update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs b/comments-and-notes/update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs new file mode 100644 index 000000000..9be0bc1c1 --- /dev/null +++ b/comments-and-notes/update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs @@ -0,0 +1,60 @@ +using System; +using System.Drawing; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +class UpdateCommentFontColor +{ + static void Main() + { + const string inputPath = "input.xlsx"; + const string outputPath = "output.xlsx"; + + try + { + // Verify that the input workbook exists + if (!File.Exists(inputPath)) + { + Console.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the workbook + Workbook workbook = new Workbook(inputPath); + + // Iterate through all worksheets + foreach (Worksheet sheet in workbook.Worksheets) + { + // Access the collection of comments on the current worksheet + CommentCollection comments = sheet.Comments; + + // Loop through each comment + for (int i = 0; i < comments.Count; i++) + { + Comment comment = comments[i]; + + // Check if the comment author is "Alice" + if (string.Equals(comment.Author, "Alice", StringComparison.OrdinalIgnoreCase)) + { + // Get the shape associated with the comment + Shape commentShape = comment.CommentShape; + + // Set the font color of the comment text to green + // For comment shapes the Font property controls the text formatting + commentShape.Font.Color = Color.Green; + } + } + } + + // Save the modified workbook + workbook.Save(outputPath); + Console.WriteLine($"Workbook saved successfully to {outputPath}"); + } + catch (Exception ex) + { + // Handle any unexpected errors + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 18600329b..ff4332007 100644 --- a/index.json +++ b/index.json @@ -44,6 +44,11 @@ "file": "set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs", "title": "Set the text direction of a comment's shape to TopToBottom for vertical annotation layout." }, + { + "category": "comments-and-notes", + "file": "update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs", + "title": "Update the font color of all comments authored by Alice to green using Shape.TextBody.Font.Color." + }, { "category": "timeline", "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", From 5bb2b05be1dafdaab3f8d21f4b626d7c5d75c7b2 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:13:50 +0500 Subject: [PATCH 10/25] Add example: apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code --- comments-and-notes/agents.md | 1 + ...recolor-with-the-appropriate-color-code.cs | 31 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 37 insertions(+) create mode 100644 comments-and-notes/apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index b32064024..83b99d8cf 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -63,3 +63,4 @@ Output files are written to the working directory. - set-the-text-direction-of-a-comments-shape-to-toptobottom-for-vertical-annotation-layout.cs - change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs - update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs +- apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs diff --git a/comments-and-notes/apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs b/comments-and-notes/apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs new file mode 100644 index 000000000..9abf3e6c1 --- /dev/null +++ b/comments-and-notes/apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs @@ -0,0 +1,31 @@ +using System; +using System.Drawing; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +class ApplyBlueBackgroundToComment +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Add a comment to cell A1 + int commentIndex = sheet.Comments.Add("A1"); + Comment comment = sheet.Comments[commentIndex]; + comment.Note = "This is a sample comment"; + + // Access the shape associated with the comment + Shape commentShape = comment.CommentShape; + + // Make sure the shape's fill is visible + commentShape.IsFilled = true; + + // Apply a solid blue background using the FillFormat's ForeColor + commentShape.FillFormat.ForeColor = Color.Blue; + + // Save the workbook + workbook.Save("CommentBlueBackground.xlsx"); + } +} \ No newline at end of file diff --git a/index.json b/index.json index ff4332007..6c4484e82 100644 --- a/index.json +++ b/index.json @@ -4,6 +4,11 @@ "language": "csharp", "framework": ".NET", "examples": [ + { + "category": "comments-and-notes", + "file": "apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs", + "title": "Apply a solid blue background to a comment using Shape.Fill.ForeColor with the appropriate color code." + }, { "category": "comments-and-notes", "file": "change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs", From 1d508f535936814822ebd046a4f0318d3cd7231b Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:16:49 +0500 Subject: [PATCH 11/25] Add example: create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format --- comments-and-notes/agents.md | 1 + ...-cells-and-save-the-file-in-xlsx-format.cs | 33 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 39 insertions(+) create mode 100644 comments-and-notes/create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 83b99d8cf..196388d21 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -64,3 +64,4 @@ Output files are written to the working directory. - change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs - update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs - apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs +- create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs diff --git a/comments-and-notes/create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs b/comments-and-notes/create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs new file mode 100644 index 000000000..8791917f4 --- /dev/null +++ b/comments-and-notes/create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs @@ -0,0 +1,33 @@ +using System; +using Aspose.Cells; + +namespace ThreadedCommentDemo +{ + class Program + { + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Get the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a threaded comment author + ThreadedCommentAuthorCollection authorCollection = workbook.Worksheets.ThreadedCommentAuthors; + int authorIndex = authorCollection.Add("John Doe", "john.doe@example.com", "PROVIDER"); + ThreadedCommentAuthor author = authorCollection[authorIndex]; + + // Access the comments collection of the worksheet + CommentCollection comments = worksheet.Comments; + + // Add threaded comments to multiple cells + comments.AddThreadedComment("A1", "First threaded comment", author); + comments.AddThreadedComment("B2", "Second threaded comment", author); + comments.AddThreadedComment("C3", "Third threaded comment", author); + + // Save the workbook in XLSX format + workbook.Save("ThreadedCommentsDemo.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 6c4484e82..7bd7c5c43 100644 --- a/index.json +++ b/index.json @@ -19,6 +19,11 @@ "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs", "title": "Create a new workbook and add a threaded comment to cell A1 with author John." }, + { + "category": "comments-and-notes", + "file": "create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs", + "title": "Create a workbook, add threaded comments to multiple cells, and save the file in XLSX format." + }, { "category": "comments-and-notes", "file": "edit-a-specific-threaded-comment-by-setting-its-text-property-to-a-new-string-value.cs", From 9d21e5d705deef7a6619c443f0188f5dd99f28a5 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:17:25 +0500 Subject: [PATCH 12/25] Add example: load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file --- comments-and-notes/agents.md | 1 + ...n-author-and-save-changes-to-a-new-file.cs | 49 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 55 insertions(+) create mode 100644 comments-and-notes/load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 196388d21..d707f3e3c 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -65,3 +65,4 @@ Output files are written to the working directory. - update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs - apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs - create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs +- load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs diff --git a/comments-and-notes/load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs b/comments-and-notes/load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs new file mode 100644 index 000000000..6bff64845 --- /dev/null +++ b/comments-and-notes/load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs @@ -0,0 +1,49 @@ +using System; +using System.Drawing; +using Aspose.Cells; + +namespace CommentFontColorModifier +{ + class Program + { + static void Main() + { + // Load the existing workbook + Workbook workbook = new Workbook("input.xlsx"); + + // Iterate through all worksheets + foreach (Worksheet sheet in workbook.Worksheets) + { + // Access the comments collection of the worksheet + CommentCollection comments = sheet.Comments; + + // Loop through each comment in the collection + for (int i = 0; i < comments.Count; i++) + { + Comment comment = comments[i]; + + // Determine the font color based on the comment author + // Example logic: Red for "Alice", Blue for "Bob", default Black otherwise + if (comment.Author != null && comment.Author.Equals("Alice", StringComparison.OrdinalIgnoreCase)) + { + comment.Font.Color = Color.Red; + } + else if (comment.Author != null && comment.Author.Equals("Bob", StringComparison.OrdinalIgnoreCase)) + { + comment.Font.Color = Color.Blue; + } + else + { + comment.Font.Color = Color.Black; + } + } + } + + // Save the modified workbook to a new file + workbook.Save("output.xlsx"); + + // Clean up + workbook.Dispose(); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 7bd7c5c43..af42c78c3 100644 --- a/index.json +++ b/index.json @@ -34,6 +34,11 @@ "file": "iterate-through-a-threadedcommentcollection-to-display-each-comments-text-author-and-creation-timestamp.cs", "title": "Iterate through a ThreadedCommentCollection to display each comment's text, author, and creation timestamp." }, + { + "category": "comments-and-notes", + "file": "load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs", + "title": "Load a workbook, modify comment font colors based on author, and save changes to a new file." + }, { "category": "comments-and-notes", "file": "load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs", From e2084b9063cdc8183892ced5e80e076622112707 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:18:01 +0500 Subject: [PATCH 13/25] Add example: batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell --- comments-and-notes/agents.md | 1 + ...omment-to-each-worksheets-top-left-cell.cs | 46 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 52 insertions(+) create mode 100644 comments-and-notes/batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index d707f3e3c..20d9ebb4c 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -66,3 +66,4 @@ Output files are written to the working directory. - apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs - create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs - load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs +- batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs diff --git a/comments-and-notes/batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs b/comments-and-notes/batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs new file mode 100644 index 000000000..570975575 --- /dev/null +++ b/comments-and-notes/batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using Aspose.Cells; + +namespace BatchDisclaimer +{ + public static class WorkbookProcessor + { + // Adds a disclaimer comment to the top‑left cell (A1) of every worksheet in all workbooks + // found in the specified folder. The original files are overwritten with the updated version. + public static void AddDisclaimerToFolder(string folderPath, string disclaimer) + { + // Get all Excel files in the folder (you can adjust the pattern if needed) + string[] files = Directory.GetFiles(folderPath, "*.xlsx", SearchOption.TopDirectoryOnly); + + foreach (string filePath in files) + { + // Load the workbook using the constructor that accepts a file path + using (Workbook workbook = new Workbook(filePath)) + { + // Iterate through each worksheet in the workbook + foreach (Worksheet sheet in workbook.Worksheets) + { + // Add a comment to cell A1 (top‑left cell) + int commentIndex = sheet.Comments.Add("A1"); + sheet.Comments[commentIndex].Note = disclaimer; + } + + // Save the modified workbook back to the same file (overwrite) + workbook.Save(filePath); + } + } + } + + // Example usage + public static void Main() + { + string folder = @"C:\ExcelFiles"; // Folder containing the workbooks + string disclaimerText = "This workbook is confidential and intended for authorized personnel only."; + + AddDisclaimerToFolder(folder, disclaimerText); + + Console.WriteLine("Disclaimer added to all workbooks in the folder."); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index af42c78c3..c4adc8f1e 100644 --- a/index.json +++ b/index.json @@ -9,6 +9,11 @@ "file": "apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs", "title": "Apply a solid blue background to a comment using Shape.Fill.ForeColor with the appropriate color code." }, + { + "category": "comments-and-notes", + "file": "batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs", + "title": "Batch process a folder of workbooks, adding a standard disclaimer comment to each worksheet's top-left cell." + }, { "category": "comments-and-notes", "file": "change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs", From 7883daaf093fd7d61aa4404663c366f718c727a7 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:18:37 +0500 Subject: [PATCH 14/25] Add example: copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text --- comments-and-notes/agents.md | 1 + ...f6-while-preserving-its-author-and-text.cs | 48 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 54 insertions(+) create mode 100644 comments-and-notes/copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 20d9ebb4c..233071c16 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -67,3 +67,4 @@ Output files are written to the working directory. - create-a-workbook-add-threaded-comments-to-multiple-cells-and-save-the-file-in-xlsx-format.cs - load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs - batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs +- copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs diff --git a/comments-and-notes/copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs b/comments-and-notes/copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs new file mode 100644 index 000000000..e39e78a6a --- /dev/null +++ b/comments-and-notes/copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs @@ -0,0 +1,48 @@ +using System; +using Aspose.Cells; + +namespace ThreadedCommentCopyDemo +{ + class Program + { + static void Main() + { + // Create a new workbook (or load an existing one) + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + CommentCollection comments = worksheet.Comments; + + // ------------------------------------------------------------ + // Ensure there is a threaded comment in cell E5 for demonstration + // ------------------------------------------------------------ + int authorIndex = workbook.Worksheets.ThreadedCommentAuthors.Add( + "Demo Author", // Name + "demoUser@example.com", // UserId + "DemoProvider"); // ProviderId + + ThreadedCommentAuthor author = workbook.Worksheets.ThreadedCommentAuthors[authorIndex]; + + // Add a threaded comment to cell E5 + comments.AddThreadedComment("E5", "Original comment text", author); + + // ------------------------------------------------------------ + // Retrieve all threaded comments from cell E5 + // ------------------------------------------------------------ + ThreadedCommentCollection sourceComments = comments.GetThreadedComments("E5"); + + // ------------------------------------------------------------ + // Copy each threaded comment to cell F6, preserving author and text + // ------------------------------------------------------------ + foreach (ThreadedComment srcComment in sourceComments) + { + // Add a new threaded comment to F6 with the same notes and author + comments.AddThreadedComment("F6", srcComment.Notes, srcComment.Author); + } + + // ------------------------------------------------------------ + // Save the workbook + // ------------------------------------------------------------ + workbook.Save("CopyThreadedComment.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index c4adc8f1e..d0c656ab5 100644 --- a/index.json +++ b/index.json @@ -19,6 +19,11 @@ "file": "change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs", "title": "Change the font color of a comment by assigning a red value to Shape.TextBody.Font.Color." }, + { + "category": "comments-and-notes", + "file": "copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs", + "title": "Copy a threaded comment from cell E5 to cell F6 while preserving its author and text." + }, { "category": "comments-and-notes", "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs", From 57284a9fa9ae6d5f61b8140c361c06e59ef8aa35 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:19:14 +0500 Subject: [PATCH 15/25] Add example: read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author --- comments-and-notes/agents.md | 1 + ...count-the-number-of-comments-per-author.cs | 46 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 52 insertions(+) create mode 100644 comments-and-notes/read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 233071c16..2046927f8 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -68,3 +68,4 @@ Output files are written to the working directory. - load-a-workbook-modify-comment-font-colors-based-on-author-and-save-changes-to-a-new-file.cs - batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs - copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs +- read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs diff --git a/comments-and-notes/read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs b/comments-and-notes/read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs new file mode 100644 index 000000000..a7536d1de --- /dev/null +++ b/comments-and-notes/read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using Aspose.Cells; + +class ThreadedCommentAuthorCounter +{ + static void Main() + { + // Load an existing workbook (replace with your file path) + Workbook workbook = new Workbook("ThreadedCommentsDemo.xlsx"); + + // Access the first worksheet (or any specific worksheet) + Worksheet worksheet = workbook.Worksheets[0]; + + // Dictionary to hold comment count per author name + Dictionary authorCommentCount = new Dictionary(StringComparer.OrdinalIgnoreCase); + + // Iterate through all comments in the worksheet + foreach (Comment comment in worksheet.Comments) + { + // Each comment may contain a collection of threaded comments + ThreadedCommentCollection threadedComments = comment.ThreadedComments; + + // Count each threaded comment by its author + foreach (ThreadedComment tc in threadedComments) + { + string authorName = tc.Author?.Name ?? "Unknown"; + + if (authorCommentCount.ContainsKey(authorName)) + authorCommentCount[authorName]++; + else + authorCommentCount[authorName] = 1; + } + } + + // Output the results + Console.WriteLine("Threaded comment count per author:"); + foreach (var kvp in authorCommentCount) + { + Console.WriteLine($"{kvp.Key}: {kvp.Value}"); + } + + // Optionally, save the workbook if any modifications were made + // workbook.Save("ThreadedCommentsDemo_Output.xlsx"); + } +} \ No newline at end of file diff --git a/index.json b/index.json index d0c656ab5..2f169a576 100644 --- a/index.json +++ b/index.json @@ -54,6 +54,11 @@ "file": "load-an-existing-workbook-retrieve-all-threaded-comments-from-column-b-and-list-their-authors.cs", "title": "Load an existing workbook, retrieve all threaded comments from column B, and list their authors." }, + { + "category": "comments-and-notes", + "file": "read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs", + "title": "Read all threaded comments from a worksheet and count the number of comments per author." + }, { "category": "comments-and-notes", "file": "remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs", From 303e9d100d959f67a1a928ca5343db27fb1a5a89 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:20:16 +0500 Subject: [PATCH 16/25] Add example: remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values --- comments-and-notes/agents.md | 1 + ...kbook-based-on-their-createdtime-values.cs | 50 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 56 insertions(+) create mode 100644 comments-and-notes/remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 2046927f8..098e63a31 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -69,3 +69,4 @@ Output files are written to the working directory. - batch-process-a-folder-of-workbooks-adding-a-standard-disclaimer-comment-to-each-worksheets-top-left-cell.cs - copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs - read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs +- remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs diff --git a/comments-and-notes/remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs b/comments-and-notes/remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs new file mode 100644 index 000000000..a58e9c8f7 --- /dev/null +++ b/comments-and-notes/remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using Aspose.Cells; + +namespace RemoveOldCommentsDemo +{ + class Program + { + static void Main() + { + const string inputPath = "input.xlsx"; + const string outputPath = "output.xlsx"; + + // Verify that the input file exists to avoid FileNotFoundException + if (!File.Exists(inputPath)) + { + Console.WriteLine($"Input file not found: {inputPath}"); + return; + } + + try + { + // Load the workbook + Workbook workbook = new Workbook(inputPath); + + // Iterate through each worksheet in the workbook + foreach (Worksheet worksheet in workbook.Worksheets) + { + CommentCollection comments = worksheet.Comments; + + // Iterate backwards so that removal does not affect the loop index + for (int i = comments.Count - 1; i >= 0; i--) + { + // Remove the comment at the current index + comments.RemoveAt(i); + } + } + + // Save the modified workbook + workbook.Save(outputPath, SaveFormat.Xlsx); + Console.WriteLine($"Workbook saved successfully to {outputPath}"); + } + catch (Exception ex) + { + // Handle any runtime errors + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 2f169a576..5fad34d39 100644 --- a/index.json +++ b/index.json @@ -64,6 +64,11 @@ "file": "remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs", "title": "Remove a threaded comment from cell C3 using the Remove method on the comment object." }, + { + "category": "comments-and-notes", + "file": "remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs", + "title": "Remove all comments older than thirty days from a workbook based on their CreatedTime values." + }, { "category": "comments-and-notes", "file": "set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs", From b71125e536ad8ce4e634605c823a54ed3903c178 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:21:01 +0500 Subject: [PATCH 17/25] Add example: scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata --- comments-and-notes/agents.md | 1 + ...ments-and-remove-them-to-clean-metadata.cs | 57 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 63 insertions(+) create mode 100644 comments-and-notes/scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 098e63a31..0dc59b59e 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -70,3 +70,4 @@ Output files are written to the working directory. - copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs - read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs - remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs +- scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs diff --git a/comments-and-notes/scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs b/comments-and-notes/scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs new file mode 100644 index 000000000..c24ab10fe --- /dev/null +++ b/comments-and-notes/scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs @@ -0,0 +1,57 @@ +using System; +using System.IO; +using Aspose.Cells; + +namespace AsposeCellsExamples +{ + public class RemoveEmptyComments + { + public static void Main(string[] args) + { + try + { + Run(); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + + public static void Run() + { + string inputPath = "input.xlsx"; + string outputPath = "output.xlsx"; + + // Ensure the input file exists before loading + if (!File.Exists(inputPath)) + { + Console.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the workbook + Workbook workbook = new Workbook(inputPath); + + // Iterate through all worksheets + foreach (Worksheet worksheet in workbook.Worksheets) + { + // Iterate backwards through comments to safely remove items + for (int i = worksheet.Comments.Count - 1; i >= 0; i--) + { + Comment comment = worksheet.Comments[i]; + + // Remove comment if its text is null, empty, or whitespace + if (string.IsNullOrWhiteSpace(comment.Note)) + { + worksheet.Comments.RemoveAt(comment.Row, comment.Column); + } + } + } + + // Save the cleaned workbook + workbook.Save(outputPath, SaveFormat.Xlsx); + Console.WriteLine($"Workbook saved to {outputPath}"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 5fad34d39..072c722bb 100644 --- a/index.json +++ b/index.json @@ -69,6 +69,11 @@ "file": "remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs", "title": "Remove all comments older than thirty days from a workbook based on their CreatedTime values." }, + { + "category": "comments-and-notes", + "file": "scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs", + "title": "Scan a workbook for empty comments and remove them to clean metadata." + }, { "category": "comments-and-notes", "file": "set-the-text-direction-of-a-comments-shape-to-righttoleft-for-bidirectional-language-support.cs", From 39da73752c55c954f95e443bbf9ed790309335ff Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:21:38 +0500 Subject: [PATCH 18/25] Add example: compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution --- comments-and-notes/agents.md | 1 + ...fying-differences-in-author-attribution.cs | 123 ++++++++++++++++++ index.json | 5 + 3 files changed, 129 insertions(+) create mode 100644 comments-and-notes/compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 0dc59b59e..390a71bd4 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -71,3 +71,4 @@ Output files are written to the working directory. - read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs - remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs - scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs +- compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs diff --git a/comments-and-notes/compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs b/comments-and-notes/compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs new file mode 100644 index 000000000..efd2f7785 --- /dev/null +++ b/comments-and-notes/compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Aspose.Cells; + +namespace ThreadedCommentComparison +{ + class Program + { + static void Main(string[] args) + { + // Paths to the two workbooks to compare + string workbookPath1 = "Workbook1.xlsx"; + string workbookPath2 = "Workbook2.xlsx"; + + // Load the workbooks (lifecycle rule: use Workbook constructor) + Workbook wb1 = new Workbook(workbookPath1); + Workbook wb2 = new Workbook(workbookPath2); + + // Extract threaded comment author information from each workbook + var commentsInfo1 = ExtractThreadedComments(wb1); + var commentsInfo2 = ExtractThreadedComments(wb2); + + // Compare the extracted information and display differences + CompareCommentAuthors(commentsInfo1, commentsInfo2); + } + + /// + /// Traverses all worksheets, cells and extracts the list of author names for each cell that contains threaded comments. + /// The key is a fully qualified cell address in the form "SheetName!A1". + /// + private static Dictionary> ExtractThreadedComments(Workbook workbook) + { + var result = new Dictionary>(StringComparer.OrdinalIgnoreCase); + + // Iterate through each worksheet + for (int wsIndex = 0; wsIndex < workbook.Worksheets.Count; wsIndex++) + { + Worksheet sheet = workbook.Worksheets[wsIndex]; + Cells cells = sheet.Cells; + + // Determine the used range to limit iteration + int maxRow = cells.MaxDataRow; + int maxCol = cells.MaxDataColumn; + + // Scan each cell within the used range + for (int row = 0; row <= maxRow; row++) + { + for (int col = 0; col <= maxCol; col++) + { + // Retrieve threaded comments for the current cell + ThreadedCommentCollection threadedComments = sheet.Comments.GetThreadedComments(row, col); + if (threadedComments != null && threadedComments.Count > 0) + { + // Build a key like "Sheet1!B2" + string cellAddress = cells[row, col].Name; // e.g., "B2" + string key = $"{sheet.Name}!{cellAddress}"; + + // Collect author names for all threaded comments in this cell + var authors = new List(); + foreach (ThreadedComment tc in threadedComments) + { + // Guard against null author (should not happen, but be safe) + if (tc.Author != null) + authors.Add(tc.Author.Name); + } + + // Store the list (order is not important for comparison) + result[key] = authors; + } + } + } + } + + return result; + } + + /// + /// Compares two dictionaries containing threaded comment author lists and prints differences. + /// + private static void CompareCommentAuthors( + Dictionary> dict1, + Dictionary> dict2) + { + // Union of all keys from both workbooks + var allKeys = new HashSet(dict1.Keys, StringComparer.OrdinalIgnoreCase); + allKeys.UnionWith(dict2.Keys); + + foreach (var key in allKeys.OrderBy(k => k)) + { + bool inFirst = dict1.TryGetValue(key, out var authors1); + bool inSecond = dict2.TryGetValue(key, out var authors2); + + if (!inFirst) + { + Console.WriteLine($"Cell {key} exists only in Workbook2 with authors: {string.Join(", ", authors2)}"); + } + else if (!inSecond) + { + Console.WriteLine($"Cell {key} exists only in Workbook1 with authors: {string.Join(", ", authors1)}"); + } + else + { + // Both workbooks have threaded comments in this cell; compare author sets + var set1 = new HashSet(authors1, StringComparer.OrdinalIgnoreCase); + var set2 = new HashSet(authors2, StringComparer.OrdinalIgnoreCase); + + if (!set1.SetEquals(set2)) + { + var onlyInFirst = set1.Except(set2); + var onlyInSecond = set2.Except(set1); + + Console.WriteLine($"Difference in authors for cell {key}:"); + if (onlyInFirst.Any()) + Console.WriteLine($" Only in Workbook1: {string.Join(", ", onlyInFirst)}"); + if (onlyInSecond.Any()) + Console.WriteLine($" Only in Workbook2: {string.Join(", ", onlyInSecond)}"); + } + } + } + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 072c722bb..823a434e2 100644 --- a/index.json +++ b/index.json @@ -19,6 +19,11 @@ "file": "change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs", "title": "Change the font color of a comment by assigning a red value to Shape.TextBody.Font.Color." }, + { + "category": "comments-and-notes", + "file": "compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs", + "title": "Compare two workbooks by extracting their threaded comments and identifying differences in author attribution." + }, { "category": "comments-and-notes", "file": "copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs", From 588b38efe229b9eaba893a42725ebd5290afddbf Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:22:24 +0500 Subject: [PATCH 19/25] Add example: read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list --- comments-and-notes/agents.md | 1 + ...ment-in-a-worksheet-and-output-the-list.cs | 53 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 59 insertions(+) create mode 100644 comments-and-notes/read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 390a71bd4..a560d60ed 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -72,3 +72,4 @@ Output files are written to the working directory. - remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs - scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs - compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs +- read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs diff --git a/comments-and-notes/read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs b/comments-and-notes/read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs new file mode 100644 index 000000000..15b51a78a --- /dev/null +++ b/comments-and-notes/read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs @@ -0,0 +1,53 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsThreadedCommentAuthors +{ + class Program + { + static void Main() + { + // Create a new workbook (lifecycle rule) + Workbook workbook = new Workbook(); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // ------------------------------------------------------------ + // Prepare sample data: add two authors and some threaded comments + // ------------------------------------------------------------ + ThreadedCommentAuthorCollection authors = workbook.Worksheets.ThreadedCommentAuthors; + + // Add authors to the collection + int aliceIndex = authors.Add("Alice", "alice@example.com", "A"); + int bobIndex = authors.Add("Bob", "bob@example.com", "B"); + + // Retrieve author objects + ThreadedCommentAuthor alice = authors[aliceIndex]; + ThreadedCommentAuthor bob = authors[bobIndex]; + + // Add a regular comment to cell A1 + Comment comment = worksheet.Comments[worksheet.Comments.Add("A1")]; + comment.Note = "Parent comment"; + + // Add threaded comments to the comment + comment.ThreadedComments.Add("First threaded comment", alice); + comment.ThreadedComments.Add("Second threaded comment", bob); + + // ------------------------------------------------------------ + // Read and output the author of each threaded comment in the worksheet + // ------------------------------------------------------------ + foreach (Comment cmt in worksheet.Comments) + { + foreach (ThreadedComment tc in cmt.ThreadedComments) + { + // Output author name + Console.WriteLine($"Threaded comment author: {tc.Author.Name}"); + } + } + + // Save the workbook (lifecycle rule) + workbook.Save("ThreadedCommentAuthorsOutput.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 823a434e2..4c9d1eb6a 100644 --- a/index.json +++ b/index.json @@ -64,6 +64,11 @@ "file": "read-all-threaded-comments-from-a-worksheet-and-count-the-number-of-comments-per-author.cs", "title": "Read all threaded comments from a worksheet and count the number of comments per author." }, + { + "category": "comments-and-notes", + "file": "read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs", + "title": "Read the author of each threaded comment in a worksheet and output the list." + }, { "category": "comments-and-notes", "file": "remove-a-threaded-comment-from-cell-c3-using-the-remove-method-on-the-comment-object.cs", From 2e991218db247ea52f913d5a9a59af79d03e6ed4 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:22:55 +0500 Subject: [PATCH 20/25] Add example: change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor --- comments-and-notes/agents.md | 1 + ...-g-to-blue-using-shapetextbodyfontcolor.cs | 44 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 50 insertions(+) create mode 100644 comments-and-notes/change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index a560d60ed..d72d2887c 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -73,3 +73,4 @@ Output files are written to the working directory. - scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs - compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs - read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs +- change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs diff --git a/comments-and-notes/change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs b/comments-and-notes/change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs new file mode 100644 index 000000000..15e9d6346 --- /dev/null +++ b/comments-and-notes/change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs @@ -0,0 +1,44 @@ +using System; +using System.Drawing; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +class ChangeCommentFontColorInColumnG +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add sample comments in column G (index 6) + for (int row = 0; row < 5; row++) + { + // Add a comment to cell G{row+1} + int commentIndex = worksheet.Comments.Add(row, 6); + Comment comment = worksheet.Comments[commentIndex]; + comment.Note = $"Comment at G{row + 1}"; + } + + // Iterate through all comments and change font color to blue for those in column G + foreach (Comment comment in worksheet.Comments) + { + if (comment.Column == 6) // Column G (zero‑based index) + { + // Access the shape associated with the comment + CommentShape shape = comment.CommentShape; + + // Use the TextBody collection to set the font color. + // The TextBody collection contains FontSetting objects; we modify the first (and only) one. + // This changes the font color of the entire comment text. + shape.TextBody[0].Font.Color = Color.Blue; + + // Ensure the comment is visible (optional) + comment.IsVisible = true; + } + } + + // Save the workbook + workbook.Save("CommentsColumnG_BlueFont.xlsx"); + } +} \ No newline at end of file diff --git a/index.json b/index.json index 4c9d1eb6a..ef4199087 100644 --- a/index.json +++ b/index.json @@ -19,6 +19,11 @@ "file": "change-the-font-color-of-a-comment-by-assigning-a-red-value-to-shapetextbodyfontcolor.cs", "title": "Change the font color of a comment by assigning a red value to Shape.TextBody.Font.Color." }, + { + "category": "comments-and-notes", + "file": "change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs", + "title": "Change the font color of comments in column G to blue using Shape.TextBody.Font.Color." + }, { "category": "comments-and-notes", "file": "compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs", From 0c35a63e0327b066085ff0e847aea772ffe842ee Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:23:25 +0500 Subject: [PATCH 21/25] Add example: add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks --- ...ext-to-cell-h2-and-preserve-line-breaks.cs | 31 +++++++++++++++++++ comments-and-notes/agents.md | 1 + index.json | 5 +++ 3 files changed, 37 insertions(+) create mode 100644 comments-and-notes/add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs diff --git a/comments-and-notes/add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs b/comments-and-notes/add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs new file mode 100644 index 000000000..bd644c010 --- /dev/null +++ b/comments-and-notes/add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs @@ -0,0 +1,31 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsThreadedCommentExample +{ + class Program + { + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Add a threaded comment author + int authorIndex = worksheet.Workbook.Worksheets.ThreadedCommentAuthors.Add( + "Demo Author", // Author name + "demo.author@example.com", // User ID (email) + "DEMO_PROVIDER"); // Provider ID + ThreadedCommentAuthor author = worksheet.Workbook.Worksheets.ThreadedCommentAuthors[authorIndex]; + + // Multi-line comment text (preserves line breaks) + string commentText = "First line of comment.\nSecond line of comment.\nThird line of comment."; + + // Add a threaded comment to cell H2 (row index 1, column index 7) + worksheet.Comments.AddThreadedComment(1, 7, commentText, author); + + // Save the workbook + workbook.Save("ThreadedComment_H2.xlsx"); + } + } +} \ No newline at end of file diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index d72d2887c..cfb15c601 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -74,3 +74,4 @@ Output files are written to the working directory. - compare-two-workbooks-by-extracting-their-threaded-comments-and-identifying-differences-in-author-attribution.cs - read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs - change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs +- add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs diff --git a/index.json b/index.json index ef4199087..8bde1f8cc 100644 --- a/index.json +++ b/index.json @@ -4,6 +4,11 @@ "language": "csharp", "framework": ".NET", "examples": [ + { + "category": "comments-and-notes", + "file": "add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs", + "title": "Add a threaded comment with multi-line text to cell H2 and preserve line breaks." + }, { "category": "comments-and-notes", "file": "apply-a-solid-blue-background-to-a-comment-using-shapefillforecolor-with-the-appropriate-color-code.cs", From 702fc5f836ad1cbe2b61af0b3239a8ff3ad468ee Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:23:59 +0500 Subject: [PATCH 22/25] Add example: retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook --- comments-and-notes/agents.md | 1 + ...threaded-comments-present-in-a-workbook.cs | 44 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 50 insertions(+) create mode 100644 comments-and-notes/retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index cfb15c601..845afa3ee 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -75,3 +75,4 @@ Output files are written to the working directory. - read-the-author-of-each-threaded-comment-in-a-worksheet-and-output-the-list.cs - change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs - add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs +- retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs diff --git a/comments-and-notes/retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs b/comments-and-notes/retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs new file mode 100644 index 000000000..0f0fefe98 --- /dev/null +++ b/comments-and-notes/retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs @@ -0,0 +1,44 @@ +using System; +using Aspose.Cells; + +namespace AsposeCellsThreadedCommentCount +{ + class Program + { + static void Main() + { + // Create a new workbook + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Add a threaded comment author + int authorIdx = workbook.Worksheets.ThreadedCommentAuthors.Add("John Doe", "john.doe@example.com", "JD"); + ThreadedCommentAuthor author = workbook.Worksheets.ThreadedCommentAuthors[authorIdx]; + + // Add some threaded comments to different cells + sheet.Comments.AddThreadedComment("A1", "First comment", author); + sheet.Comments.AddThreadedComment("A1", "Reply to first", author); + sheet.Comments.AddThreadedComment("B2", "Another comment", author); + + // Variable to hold total count + int totalThreadedComments = 0; + + // Iterate through all worksheets + foreach (Worksheet ws in workbook.Worksheets) + { + // Iterate through all comments in the worksheet + foreach (Comment comment in ws.Comments) + { + // Each comment may contain a collection of threaded comments + totalThreadedComments += comment.ThreadedComments.Count; + } + } + + // Display the total number of threaded comments + Console.WriteLine($"Total threaded comments in the workbook: {totalThreadedComments}"); + + // Save the workbook (optional, just to demonstrate lifecycle usage) + workbook.Save("ThreadedCommentsCount.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 8bde1f8cc..612b109d7 100644 --- a/index.json +++ b/index.json @@ -89,6 +89,11 @@ "file": "remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs", "title": "Remove all comments older than thirty days from a workbook based on their CreatedTime values." }, + { + "category": "comments-and-notes", + "file": "retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs", + "title": "Retrieve and display the total number of threaded comments present in a workbook." + }, { "category": "comments-and-notes", "file": "scan-a-workbook-for-empty-comments-and-remove-them-to-clean-metadata.cs", From a850e2f89cfc2f0ca5b6dac33b5b46c65a3eb2d0 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:24:41 +0500 Subject: [PATCH 23/25] Add example: update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout --- comments-and-notes/agents.md | 1 + ...heet-to-lefttoright-for-standard-layout.cs | 48 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 54 insertions(+) create mode 100644 comments-and-notes/update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 845afa3ee..eadfd0758 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -76,3 +76,4 @@ Output files are written to the working directory. - change-the-font-color-of-comments-in-column-g-to-blue-using-shapetextbodyfontcolor.cs - add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs - retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs +- update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs diff --git a/comments-and-notes/update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs b/comments-and-notes/update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs new file mode 100644 index 000000000..5cd557654 --- /dev/null +++ b/comments-and-notes/update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using Aspose.Cells; + +namespace AsposeCellsDemo +{ + class UpdateCommentTextDirection + { + static void Main() + { + string inputPath = "input.xlsx"; + string outputPath = "output.xlsx"; + + try + { + // Verify that the input file exists + if (!File.Exists(inputPath)) + { + Console.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the workbook + Workbook workbook = new Workbook(inputPath); + + // Access the first worksheet + Worksheet worksheet = workbook.Worksheets[0]; + + // Update text direction for each comment + foreach (Comment comment in worksheet.Comments) + { + if (comment.CommentShape != null) + { + comment.CommentShape.TextDirection = TextDirectionType.LeftToRight; + } + } + + // Save the updated workbook + workbook.Save(outputPath); + Console.WriteLine($"Workbook saved to {outputPath}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 612b109d7..2f1fe0d10 100644 --- a/index.json +++ b/index.json @@ -114,6 +114,11 @@ "file": "update-the-font-color-of-all-comments-authored-by-alice-to-green-using-shapetextbodyfontcolor.cs", "title": "Update the font color of all comments authored by Alice to green using Shape.TextBody.Font.Color." }, + { + "category": "comments-and-notes", + "file": "update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs", + "title": "Update the text direction of all comments in a worksheet to LeftToRight for standard layout." + }, { "category": "timeline", "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", From fefd7bc6a6816fce745ebcafed924813a158ebcd Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:25:53 +0500 Subject: [PATCH 24/25] Add example: replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image --- comments-and-notes/agents.md | 1 + ...t-with-a-semi-transparent-overlay-image.cs | 40 +++++++++++++++++++ index.json | 5 +++ 3 files changed, 46 insertions(+) create mode 100644 comments-and-notes/replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index eadfd0758..12ecb76bb 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -77,3 +77,4 @@ Output files are written to the working directory. - add-a-threaded-comment-with-multi-line-text-to-cell-h2-and-preserve-line-breaks.cs - retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs - update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs +- replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs diff --git a/comments-and-notes/replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs b/comments-and-notes/replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs new file mode 100644 index 000000000..5f7f279cd --- /dev/null +++ b/comments-and-notes/replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +class ReplaceCommentBackground +{ + static void Main() + { + try + { + // Create a new workbook + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Add a comment to cell B2 + int commentIdx = sheet.Comments.Add("B2"); + Comment comment = sheet.Comments[commentIdx]; + comment.Note = "Original comment"; + + // Load overlay image if it exists + string overlayPath = "overlay.png"; + if (!File.Exists(overlayPath)) + throw new FileNotFoundException($"Overlay image not found: {overlayPath}"); + + byte[] overlayBytes = File.ReadAllBytes(overlayPath); + + // Set the overlay image as the comment background + comment.CommentShape.Fill.ImageData = overlayBytes; // picture fill + comment.CommentShape.Fill.Transparency = 0.5; // 50 % transparent + + // Save the workbook + workbook.Save("CommentWithOverlay.xlsx"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index 2f1fe0d10..fb7d1cfcb 100644 --- a/index.json +++ b/index.json @@ -89,6 +89,11 @@ "file": "remove-all-comments-older-than-thirty-days-from-a-workbook-based-on-their-createdtime-values.cs", "title": "Remove all comments older than thirty days from a workbook based on their CreatedTime values." }, + { + "category": "comments-and-notes", + "file": "replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs", + "title": "Replace the background picture of a comment with a semi-transparent overlay image." + }, { "category": "comments-and-notes", "file": "retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs", From 63bb93f9f580c3e0306cde0f0c202ee0f3db5ca5 Mon Sep 17 00:00:00 2001 From: agent-aspose-cells-examples Date: Tue, 19 May 2026 03:27:23 +0500 Subject: [PATCH 25/25] Add example: copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment --- comments-and-notes/agents.md | 1 + ...color-and-font-color-to-another-comment.cs | 58 +++++++++++++++++++ index.json | 5 ++ 3 files changed, 64 insertions(+) create mode 100644 comments-and-notes/copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment.cs diff --git a/comments-and-notes/agents.md b/comments-and-notes/agents.md index 12ecb76bb..dc1d4ef4c 100644 --- a/comments-and-notes/agents.md +++ b/comments-and-notes/agents.md @@ -78,3 +78,4 @@ Output files are written to the working directory. - retrieve-and-display-the-total-number-of-threaded-comments-present-in-a-workbook.cs - update-the-text-direction-of-all-comments-in-a-worksheet-to-lefttoright-for-standard-layout.cs - replace-the-background-picture-of-a-comment-with-a-semi-transparent-overlay-image.cs +- copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment.cs diff --git a/comments-and-notes/copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment.cs b/comments-and-notes/copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment.cs new file mode 100644 index 000000000..0405f1fa0 --- /dev/null +++ b/comments-and-notes/copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment.cs @@ -0,0 +1,58 @@ +using System; +using System.Drawing; +using Aspose.Cells; +using Aspose.Cells.Drawing; + +namespace AsposeCellsCommentFormattingCopy +{ + class Program + { + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet worksheet = workbook.Worksheets[0]; + + // Access the comments collection of the worksheet + CommentCollection comments = worksheet.Comments; + + // ------------------------------------------------- + // Create source comment (A1) and set its shape format + // ------------------------------------------------- + int srcIndex = comments.Add("A1"); + Comment srcComment = comments[srcIndex]; + srcComment.Note = "Source comment"; + + // Set background color (fill) of the source comment shape + CommentShape srcShape = srcComment.CommentShape; + srcShape.Fill.FillType = FillType.Solid; + srcShape.Fill.SolidFill.Color = Color.LightYellow; // background color + + // Set font color of the source comment shape + srcShape.Font.Color = Color.Blue; // font color + + // ------------------------------------------------- + // Create destination comment (B2) – formatting will be copied + // ------------------------------------------------- + int destIndex = comments.Add("B2"); + Comment destComment = comments[destIndex]; + destComment.Note = "Destination comment"; + + // Get the shape of the destination comment + CommentShape destShape = destComment.CommentShape; + + // ------------------------------- + // Copy formatting from source to destination + // ------------------------------- + // Copy background (fill) settings + destShape.Fill.FillType = srcShape.Fill.FillType; + destShape.Fill.SolidFill.Color = srcShape.Fill.SolidFill.Color; + + // Copy font color + destShape.Font.Color = srcShape.Font.Color; + + // Save the workbook to verify the result + workbook.Save("CommentFormattingCopy.xlsx"); + } + } +} \ No newline at end of file diff --git a/index.json b/index.json index fb7d1cfcb..bdeb042bc 100644 --- a/index.json +++ b/index.json @@ -39,6 +39,11 @@ "file": "copy-a-threaded-comment-from-cell-e5-to-cell-f6-while-preserving-its-author-and-text.cs", "title": "Copy a threaded comment from cell E5 to cell F6 while preserving its author and text." }, + { + "category": "comments-and-notes", + "file": "copy-formatting-of-a-comments-shape-including-background-color-and-font-color-to-another-comment.cs", + "title": "Copy formatting of a comment's shape, including background color and font color, to another comment." + }, { "category": "comments-and-notes", "file": "create-a-new-workbook-and-add-a-threaded-comment-to-cell-a1-with-author-john.cs",