VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
В этом разделе
XLSX: Работа с комментариями на странице XLSX
В этом разделе
UI-контролы SpreadsheetEditorControl и WpfSpreadsheetEditorControl позволяют работать (просматривать, добавлять, редактировать и удалять) с комментариями к ячейкам рабочего листа XLSX в настольном приложении (WinForms, WPF).
Комментарии к ячейке можно изменить визуально с помощью мыши/клавиатуры или программно.


Добавление комментария к выделенной ячейке рабочего листа XLSX.

Вот C#/VB.NET код, который демонстрирует, как добавить комментарий к выделенной ячейке рабочего листа XLSX:
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


Редактирование комментария выделенной ячейки рабочего листа XLSX.

Вот C#/VB.NET код, который демонстрирует, как изменить комментарий выделенной ячейки рабочего листа XLSX:
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


Изменение размера комментария выделенной ячейки рабочего листа XLSX

Если вы хотите изменить размер комментария выделенной ячейке рабочего листа XLSX с помощью мыши, вам следует выполнить следующие действия:

Перемещение комментария выделенной ячейки рабочего листа XLSX

Если вы хотите переместить комментарий выделенной ячейки рабочего листа XLSX с помощью мыши, необходимо выполнить следующие действия:

Изменение свойств шрифта выделенного комментария на листе XLSX

Вот C#/VB.NET код, который демонстрирует, как изменить свойства шрифта сфокусированного комментария на листе XLSX:
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


Изменение свойств текста сфокусированного комментария на листе XLSX

Вот C#/VB.NET код, который демонстрирует, как изменить свойства текста сфокусированного комментария на листе XLSX:
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


Изменение цвета фона сфокусированного комментария на листе XLSX

Вот C#/VB.NET код, который демонстрирует, как изменить цвет фона сфокусированного комментария на листе XLSX:
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


Удаление комментария выделенной ячейки на листе XLSX

Если вы хотите удалить сфокусированный комментарий на листе XLSX с помощью мыши , вам следует выполнить следующие действия:
Вот C#/VB.NET код, который демонстрирует, как удалить комментарий выделенной ячейки рабочего листа XLSX:
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