【问题标题】:Accessing Comment Changes in a Spreadsheetgear WorkbookView Control访问电子表格工作簿视图控件中的注释更改
【发布时间】:2023-03-26 17:38:01
【问题描述】:

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

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

【问题讨论】:

    标签: spreadsheetgear


    【解决方案1】:

    在我阅读 Joe 的回复之前不知道单独保存 cmets 的方法,我决定通过遍历 workbookView 中的单元格并在表单关闭时抓取 cmets 来保存 cmets。

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

    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;
      }
    }
    

    【讨论】:

      【解决方案2】:

      很遗憾,答案是“有点但不是真的”。

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

          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 的支持人员发送电子邮件请求此功能,他们会将此功能请求添加到他们的列表中,并附上您的电子邮件地址。

      【讨论】:

      • 乔,感谢您的代码。它使我找到了一个似乎可行的解决方案,我在下面的答案中发布了该解决方案。
      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      相关资源
      最近更新 更多