XLSX: Work with comments on XLSX page
In This Topic
SpreadsheetEditorControl and
WpfSpreadsheetEditorControl controls allow to work (view, add, edit and delete) with comments to the cells of XLSX worksheet in desktop (WinForms, WPF) application.
Cell comments can be changed visually using mouse/keyboard or programmatically.
Add a comment to the focused cell of XLSX worksheet
Here is C#/VB.NET code that demonstrates how to add a comment to the focused cell of XLSX worksheet:
public void AddCommentToXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// prepare parameters of comment
// comment author
string commentAuthor = "Person";
// a value indicating whether author name must be shown in comment
bool showAuthor = true;
// comment color
Vintasoft.Primitives.VintasoftColor color = Vintasoft.Primitives.VintasoftColor.FromRgb(128, 128, 192);
// comment text
string commentText = "Test comment text";
// text properties
Vintasoft.Imaging.Office.Spreadsheet.Document.TextProperties textProperties =
new Vintasoft.Imaging.Office.Spreadsheet.Document.TextProperties(
Vintasoft.Imaging.Office.Spreadsheet.Document.TextHorizontalAlign.Left,
Vintasoft.Imaging.Office.Spreadsheet.Document.TextVerticalAlign.Middle,
true,
0);
// font properties
Vintasoft.Imaging.Office.Spreadsheet.Document.FontProperties fontProperties =
new Vintasoft.Imaging.Office.Spreadsheet.Document.FontProperties(
"Arial", 12, Vintasoft.Primitives.VintasoftColor.Black);
// create new comment
Vintasoft.Imaging.Office.Spreadsheet.Document.Comment comment =
new Vintasoft.Imaging.Office.Spreadsheet.Document.Comment(
commentAuthor,
showAuthor,
color,
commentText,
textProperties,
fontProperties);
// get the focused cell
Vintasoft.Imaging.Office.Spreadsheet.Document.CellReference focusedCell = spreadsheetVisualEditor.FocusedCell;
// comment location
Vintasoft.Imaging.Office.Spreadsheet.Document.SheetDrawingLocation location =
new Vintasoft.Imaging.Office.Spreadsheet.Document.SheetDrawingLocation(new Vintasoft.Primitives.VintasoftRect(100, 100, 200, 100));
// create cell comment
Vintasoft.Imaging.Office.Spreadsheet.Document.CellComment cellComment =
new Vintasoft.Imaging.Office.Spreadsheet.Document.CellComment(focusedCell, comment, true, location);
// set comment to the focused cell
spreadsheetVisualEditor.SetCellComment(cellComment);
}
Public Sub AddCommentToXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' prepare parameters of comment
' comment author
Dim commentAuthor As String = "Person"
' a value indicating whether author name must be shown in comment
Dim showAuthor As Boolean = True
' comment color
Dim color As Vintasoft.Primitives.VintasoftColor = Vintasoft.Primitives.VintasoftColor.FromRgb(128, 128, 192)
' comment text
Dim commentText As String = "Test comment text"
' text properties
Dim textProperties As New Vintasoft.Imaging.Office.Spreadsheet.Document.TextProperties(Vintasoft.Imaging.Office.Spreadsheet.Document.TextHorizontalAlign.Left, Vintasoft.Imaging.Office.Spreadsheet.Document.TextVerticalAlign.Middle, True, 0)
' font properties
Dim fontProperties As New Vintasoft.Imaging.Office.Spreadsheet.Document.FontProperties("Arial", 12, Vintasoft.Primitives.VintasoftColor.Black)
' create new comment
Dim comment As New Vintasoft.Imaging.Office.Spreadsheet.Document.Comment(commentAuthor, showAuthor, color, commentText, textProperties, fontProperties)
' get the focused cell
Dim focusedCell As Vintasoft.Imaging.Office.Spreadsheet.Document.CellReference = spreadsheetVisualEditor.FocusedCell
' comment location
Dim location As New Vintasoft.Imaging.Office.Spreadsheet.Document.SheetDrawingLocation(New Vintasoft.Primitives.VintasoftRect(100, 100, 200, 100))
' create cell comment
Dim cellComment As New Vintasoft.Imaging.Office.Spreadsheet.Document.CellComment(focusedCell, comment, True, location)
' set comment to the focused cell
spreadsheetVisualEditor.SetCellComment(cellComment)
End Sub
Edit the comment of the focused cell of XLSX worksheet
Here is C#/VB.NET code that demonstrates how to change the comment of focused cell of XLSX worksheet:
public void ChangeCommentOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// if focused cell does not have comment
if (spreadsheetVisualEditor.FocusedCellComment == null)
throw new System.Exception("Focused cell does not have comment.");
// get source cell comment (the cell with comment should be focused)
Vintasoft.Imaging.Office.Spreadsheet.Document.CellComment sourceCellComment =
spreadsheetVisualEditor.FocusedComment ?? spreadsheetVisualEditor.FocusedCellComment;
Vintasoft.Imaging.Office.Spreadsheet.Document.Comment sourceComment = sourceCellComment.Comment;
// prepare parameters to change in comment
// comment author
string commentAuthor = "User";
// comment color
Vintasoft.Primitives.VintasoftColor color = Vintasoft.Primitives.VintasoftColor.FromRgb(128, 192, 128);
// comment text
string commentText = "Comment changed!";
// create new comment with changed properties
Vintasoft.Imaging.Office.Spreadsheet.Document.Comment comment =
new Vintasoft.Imaging.Office.Spreadsheet.Document.Comment(
commentAuthor,
sourceComment.ShowAuthor,
color,
commentText,
sourceComment.TextProperties,
sourceComment.FontProperties);
// set comment to the focused cell
spreadsheetVisualEditor.SetComment(comment);
}
Public Sub ChangeCommentOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' if focused cell does not have comment
If spreadsheetVisualEditor.FocusedCellComment Is Nothing Then
Throw New System.Exception("Focused cell does not have comment.")
End If
' get source cell comment (the cell with comment should be focused)
Dim sourceCellComment As Vintasoft.Imaging.Office.Spreadsheet.Document.CellComment = If(spreadsheetVisualEditor.FocusedComment, spreadsheetVisualEditor.FocusedCellComment)
Dim sourceComment As Vintasoft.Imaging.Office.Spreadsheet.Document.Comment = sourceCellComment.Comment
' prepare parameters to change in comment
' comment author
Dim commentAuthor As String = "User"
' comment color
Dim color As Vintasoft.Primitives.VintasoftColor = Vintasoft.Primitives.VintasoftColor.FromRgb(128, 192, 128)
' comment text
Dim commentText As String = "Comment changed!"
' create new comment with changed properties
Dim comment As New Vintasoft.Imaging.Office.Spreadsheet.Document.Comment(commentAuthor, sourceComment.ShowAuthor, color, commentText, sourceComment.TextProperties, sourceComment.FontProperties)
' set comment to the focused cell
spreadsheetVisualEditor.SetComment(comment)
End Sub
Resize the comment of the focused cell of XLSX worksheet
If you want to resize the comment of the focused cell of XLSX worksheet using mouse, you should do the following steps:
- Click on the comment that should be resized and you will see 8 resizing points, which allow to resize the comment using mouse
- Click on any resizing point and move mouse to resize the comment
Move the comment of the focused cell of XLSX worksheet
If you want to move (reposition) the comment of the focused cell of XLSX worksheet using mouse, you should do the following steps:
- Hover the comment with mouse cursor and you will see the move cursor
- Click on the comment and move the mouse to the new position
Change the font properties of focused comment of XLSX worksheet
Here is C#/VB.NET code that demonstrates how to change the font properties of focused comment of XLSX worksheet:
public void ChangeFontPropertiesOfXlsxComment(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// if focused cell does not have comment
if (spreadsheetVisualEditor.FocusedCellComment == null)
throw new System.Exception("Focused cell does not have comment.");
// select comment
if (spreadsheetVisualEditor.FocusedComment == null)
spreadsheetVisualEditor.FocusedComment = spreadsheetVisualEditor.FocusedCellComment;
// set new font name
spreadsheetVisualEditor.FontName = "Times New Roman";
// set new font size
spreadsheetVisualEditor.FontSize = 16;
// set new boldness value
spreadsheetVisualEditor.IsFontBold = true;
// set new italic font value
spreadsheetVisualEditor.IsFontItalic = true;
// set new underline font value
spreadsheetVisualEditor.IsFontUnderline = true;
// set new strikeout font value
spreadsheetVisualEditor.IsFontStrikeout = true;
// set new font color
spreadsheetVisualEditor.FontColor = Vintasoft.Primitives.VintasoftColor.Red;
}
Public Sub ChangeFontPropertiesOfXlsxComment(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' if focused cell does not have comment
If spreadsheetVisualEditor.FocusedCellComment Is Nothing Then
Throw New System.Exception("Focused cell does not have comment.")
End If
' select comment
If spreadsheetVisualEditor.FocusedComment Is Nothing Then
spreadsheetVisualEditor.FocusedComment = spreadsheetVisualEditor.FocusedCellComment
End If
' set new font name
spreadsheetVisualEditor.FontName = "Times New Roman"
' set new font size
spreadsheetVisualEditor.FontSize = 16
' set new boldness value
spreadsheetVisualEditor.IsFontBold = True
' set new italic font value
spreadsheetVisualEditor.IsFontItalic = True
' set new underline font value
spreadsheetVisualEditor.IsFontUnderline = True
' set new strikeout font value
spreadsheetVisualEditor.IsFontStrikeout = True
' set new font color
spreadsheetVisualEditor.FontColor = Vintasoft.Primitives.VintasoftColor.Red
End Sub
Change the text properties of focused comment of XLSX worksheet
Here is C#/VB.NET code that demonstrates how to change the text properties of focused comment of XLSX worksheet:
public void ChangeTextPropertiesOfXlsxComment(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// if focused cell does not have comment
if (spreadsheetVisualEditor.FocusedCellComment == null)
throw new System.Exception("Focused cell does not have comment.");
// select comment
if (spreadsheetVisualEditor.FocusedComment == null)
spreadsheetVisualEditor.FocusedComment = spreadsheetVisualEditor.FocusedCellComment;
// set new text horizontal alignment
spreadsheetVisualEditor.TextHorizontalAlign =
Vintasoft.Imaging.Office.Spreadsheet.Document.TextHorizontalAlign.Center;
// set new text vertical alignment
spreadsheetVisualEditor.TextVerticalAlign =
Vintasoft.Imaging.Office.Spreadsheet.Document.TextVerticalAlign.Bottom;
}
Public Sub ChangeTextPropertiesOfXlsxComment(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' if focused cell does not have comment
If spreadsheetVisualEditor.FocusedCellComment Is Nothing Then
Throw New System.Exception("Focused cell does not have comment.")
End If
' select comment
If spreadsheetVisualEditor.FocusedComment Is Nothing Then
spreadsheetVisualEditor.FocusedComment = spreadsheetVisualEditor.FocusedCellComment
End If
' set new text horizontal alignment
spreadsheetVisualEditor.TextHorizontalAlign = Vintasoft.Imaging.Office.Spreadsheet.Document.TextHorizontalAlign.Center
' set new text vertical alignment
spreadsheetVisualEditor.TextVerticalAlign = Vintasoft.Imaging.Office.Spreadsheet.Document.TextVerticalAlign.Bottom
End Sub
Change the background color of focused comment of XLSX worksheet
Here is C#/VB.NET code that demonstrates how to change the background color of focused comment of XLSX worksheet:
public void ChangeBackgroundOfXlsxComment(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// if focused cell does not have comment
if (spreadsheetVisualEditor.FocusedCellComment == null)
throw new System.Exception("Focused cell does not have comment.");
// select comment
if (spreadsheetVisualEditor.FocusedComment == null)
spreadsheetVisualEditor.FocusedComment = spreadsheetVisualEditor.FocusedCellComment;
// set new comment background color
spreadsheetVisualEditor.FillColor = Vintasoft.Primitives.VintasoftColor.Green;
}
Public Sub ChangeBackgroundOfXlsxComment(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' if focused cell does not have comment
If spreadsheetVisualEditor.FocusedCellComment Is Nothing Then
Throw New System.Exception("Focused cell does not have comment.")
End If
' select comment
If spreadsheetVisualEditor.FocusedComment Is Nothing Then
spreadsheetVisualEditor.FocusedComment = spreadsheetVisualEditor.FocusedCellComment
End If
' set new comment background color
spreadsheetVisualEditor.FillColor = Vintasoft.Primitives.VintasoftColor.Green
End Sub
Delete the comment of focused cell of XLSX worksheet
If you want to delete the focused comment of XLSX worksheet using mouse, you should do the following steps:
- Click on the comment that should be deleted
- Press "Del" key.
Here is C#/VB.NET code that demonstrates how to delete the comment of the focused cell of XLSX worksheet:
public void DeleteCommentOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// remove comments from selected cells
spreadsheetVisualEditor.RemoveComments();
}
Public Sub DeleteCommentOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' remove comments from selected cells
spreadsheetVisualEditor.RemoveComments()
End Sub