UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

工作流活动

从数据网格组件读取单元格值

You can read the cell values from a Data Grid component. For example, you will learn how to dynamically sum all values in a Data Grid column. For any new item, the Total Quantity field displays the new total value.

教程

要使用此功能,请执行以下操作:

  1. Add the Create Form activity to your workflow.
  2. Open the Form Designer from the Create Form activity.
  3. Drag and drop a Data Grid component.
  4. Inside the Data Grid component, drag and drop one Text Field component to store the item name (label it as Item).
  5. Inside the Data Grid component, drag and drop one Number component to store the item quantity (label it as Quantity).
  6. 在“数据网格”组件之外,拖放一个“文本字段”组件,以显示“数据网格”中所有项目的总数。 这需要高级逻辑。
    1. 将组件标记为总数量

    2. 选择组件“显示”选项卡上的“已禁用”复选框。这会使该字段变为只读。

    3. “逻辑”选项卡上,单击“添加逻辑”以配置触发器和操作以对值求和。

    4. “触发器”部分 > “逻辑名称”字段中,输入逻辑的名称。

    5. 在“类型”中选择“简单” 。将其余字段留空,以便更改任何数据网格的逻辑触发器。

    6. “操作”部分 > “操作名称”字段中,输入操作的名称。在本例中,触发的操作是更新总计值,因此我们使用updateValue作为操作名称。

    7. Select the Value action type, and enter the following script in the Value (Javascript) section:

      var result = 0;
      for (var i = 0; i < data.dataGrid.length; i++) {
        result += +(data.dataGrid[i].number);
      }
      return result;
      var result = 0;
      for (var i = 0; i < data.dataGrid.length; i++) {
        result += +(data.dataGrid[i].number);
      }
      return result;
      

      上面的代码片段遍历数据网格中的现有值并汇总它们。任何新值都会重新启动迭代,从而更新总值。

    8. 保存操作和逻辑。

    9. 保存“文本字段”组件。

  7. 保存表单。
  8. At runtime, when you add a new item to the grid, notice the Total Quantity value being updated.

示例工作流

要查看完整的工作流或供日后参考,请下载XAML 示例

  • 教程
  • 示例工作流

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新