Notes
Since R1 2022 the SpreadProcessing library supports working with notes. The Notes are used for making notes or annotations about the data. All notes can be found in the NoteCollection of the worksheet. This collection holds SpreadsheetNote objects which represent the notes. Each note has the following properties:
- CellIndex: Gets or sets the cell index where the top left corner of the shape is positioned.
- RelatedCellIndex: Gets or sets the cell index assigned to the note.
- AlternateText: Gets or sets the alternate text.
- IsVisible: Gets or sets a value indicating whether this SpreadsheetNote is visible.
- OffsetX: Gets or sets the left offset of the top left corner of the shape relative to the top left corner of the cell index.
- OffsetY: Gets or sets the top offset of the top left corner of the shape relative to the top left corner of the cell index.
- Width: Gets or sets the width of the shape.
- Height: Gets or sets the height of the shape.
- MoveWithCells: Gets or sets a value indicating whether this SpreadsheetNote moves with its underlying cells.
- SizeWithCells: Gets or sets a value indicating whether this SpreadsheetNote resizes with its underlying cells.
-
Author: Gets or sets the author assigned to the note.
- Text: Gets or sets the text.
- Id: Gets the id of the shape, which is unique for the worksheet it belongs to.
- Name: Gets or sets the name of the shape.
- LockAspectRatio: Gets or sets the value indicating whether the aspect ratio between the width and height should remain constant.
All of the above properties will push a change to the undo stack when modified.
Working with the NoteCollection
Adding notes
To add a note you need to specify the cell index to which the note will be related, the position where the note should be placed, the author, and the text content. Specifying the position is optional and by default, the note is placed next to the related cell.
Example 1: Add note
CellIndex relatedCellIndex = new CellIndex(1, 1);
CellIndex cellIndex = new CellIndex(5, 5);
string author = "John Doe";
string text = "Comment Content";
worksheet.Notes.Add(relatedCellIndex, cellIndex, author, text);
Removing Notes
Example 2: Remove note
var note = worksheet.Notes[0];
worksheet.Notes.Remove(note);
Hide/Show notes
You can use one of the following methods to show/hide single or all notes:
- ShowAll: Shows all notes in the collection.
- HideAll: Hides all notes in the collection.
- Hide(SpreadsheetNote note): Hide the specified note from the collection.
- Show(SpreadsheetNote note): Show the specified note from the collection.
Example 3:Hide note
var note = worksheet.Notes[0];
worksheet.Notes.Hide(note);
Events
The notes collection exposes the following events:
- Changing: Occurs when the collection is being changed.
- Changed: Occurs when the collection has changed.
- NotesVisiblilityChanged: Occurs when the visibility of all notes has been changed at the same time.