访问Spreadsheetgear WorkbookView控件中的注释更改

时间:2009-08-12 16:43:00

标签: spreadsheetgear

我有一个使用SpreadsheetGear的WorkbookView控件的C#应用​​程序。用户希望能够对保存的单元格的注释进行更改。

有人知道在用户编辑评论时捕获更改的方法。编辑评论时不会触发单元格编辑事件,我找不到任何方法来捕获用户对评论所做的更改。

2 个答案:

答案 0 :(得分:3)

在我读回Joe的回复并不知道单独保存注释的方法之前,我决定通过循环遍历工作簿View中的单元格来保存注释,并在表单关闭时抓取注释。

在看到他的回复之后,我找到了一种方法,在使用workbookView1_ShapeSelectionChanged和workbookView1_ShapeAction事件的组合输入后立即获得评论。打开注释框进行编辑以及关闭注释框进行编辑时,将触发workbookView1_ShapeSelectionChanged事件。当它为评论框打开时触发,我得到ActiveCell,因为当评论框关闭时它可能不再是ActiveCell。如果评论已更改,我会在评论框关闭时使用该单元格来获取评论。每次在注释框中输入新字符时,都会触发workbookView1_ShapeAction事件,这对于将注释标记为已更改非常有用。保存注释后,commentChanged变量将设置回false。以下是使用Joe在其答案中发布的代码的代码:

private void workbookView1_ShapeAction(object sender, SpreadsheetGear.Windows.Forms.ShapeActionEventArgs e)
{
  switch (e.ShapeActionType)
  {
    case SpreadsheetGear.Windows.Forms.ShapeActionType.TextChanged:
      if (e.Shape.Type == SpreadsheetGear.Shapes.ShapeType.Comment)
      {
        //set comment changed flag to true
        _commentChanged = true;
      }
      break;
  } 
}

private void workbookView1_ShapeSelectionChanged(object sender, SpreadsheetGear.Windows.Forms.ShapeSelectionChangedEventArgs e)
{
  if (_commentChanged)
  {
    //get comment
    string comment = _commentCell.Comment.Shape.TextFrame.Characters.Text;

    //save comment
    //....

    //set comment changed flag to false
    _commentChanged = false;
  }
  else
  {
    //get the cell whose comment is being edited
    _commentCell = workbookView1.ActiveCell;
  }
}

答案 1 :(得分:1)

不幸的是,答案是“有点但不是真的”。

您可以捕获ShapeAction事件,如下所示,但ShapeAction事件实际上是为形状而不是注释设计的,因此您无法获取当前文本(文本尚未存储在形状中),您甚至无法获得评论所属的单元格。不过,我会粘贴一些代码,因为它可能对您有用:

    private void workbookView1_ShapeAction(object sender, SpreadsheetGear.Windows.Forms.ShapeActionEventArgs e)
    {
        switch (e.ShapeActionType)
        {
            case SpreadsheetGear.Windows.Forms.ShapeActionType.TextChanged:
                if (e.Shape.Type == SpreadsheetGear.Shapes.ShapeType.Comment)
                {
                    // Unfortunately, this is as far as we can get since IShape
                    // does not have a way to get back to the cell which owns the comment.
                    //
                    // Furthermore, the text is not yet stored in the IShape, so we
                    // cannot get the current text either.
                }
                break;
        }
    }

如果您向SpreadsheetGear的支持部门发送电子邮件,要求此功能,他们会将此功能请求添加到其列表中,并附上您的电子邮件地址。

相关问题