UiPath Documentation
studiox
2024.10
true
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

StudioX user guide

上次更新日期 2026年4月30日

教程:使用 Word 自动化

在本教程中,我们将创建一个自动化,其将基于模板 Word 文件以及从多个 Excel 和文本文件收集的数据为团队的每个成员生成单独的绩效评估 Word 文档。模板文件中包含的占位符文本和书签可以用使用 Word 活动的值来填充。所复制数据的来源 Excel 文件和文本文件的名称遵循包含员工姓名的特定模式。

We will start by adding a Use Excel File activity to indicate an Excel file with employee information to add to the automation. Inside it, we will add a For Each Excel Row activity to iterate through the rows with employee data. Inside For Each Excel Row, we will add a Use Word File activity to add the template document to the automation, and then a series of Replace Text, Set Bookmark Content, and Insert DataTable in Document activities will populate each Word file with the necessary information taken for each employee from an Excel file and a text file. Finally, we will add a Save Word File As activity to save the template document as a separate file for each employee.

  1. 设置项目并获取必要的文件。
    1. Create a new blank project using the default settings.
    2. 使用此页面底部的按钮,下载并解压缩本教程中自动化项目的存档文件。将文件夹 Files 复制到您的项目文件夹。
    3. 在项目文件夹中创建一个名为 Output 的文件夹。
  2. 将包含员工数据的 Excel 添加到项目中,并遍历文件中的行。
    1. In StudioX, click Add Activity 文档图像 in the Designer panel, and then find the Use Excel File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    2. 在活动中:
      • Click Browse 文档图像 next to the Excel file field, and then browse to the Files folder and select the file Employees.xlsx.

      • 在“引用为”字段中,输入 EmployeeData

        您已表明将使用在自动化中称为 EmployeeData 的 Employees.xlsx 文件。

    3. Click Add Activity 文档图像 inside Use Excel File, and then find the For Each Excel Row activity in the search box at the top of the screen and select it. The activity is added to the Designer panel inside the Use Excel File activity.
    4. 在“遍历 Excel 行”活动中:
      • 在“遍历”文本框中,将 CurrentRow 替换为 Employee

      • Click Plus docs image on the right side of the In range field, and then select EmployeeData > Sheet1 [Sheet].

        您已表明要遍历“Employees”电子表格中 Sheet1 中的行。由于每一行都包含有关员工的信息,因此迭代中的当前行被重命名为 Employee,以便稍后在自动化中更容易识别该行中的信息。

        文档图像

  3. 将模板 Word 文件添加到自动化中。
    1. Click Add Activity 文档图像 inside For Each Excel Row, and then find the Use Word File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    2. 在"使用 Word 文件"活动中:
      • Click Browse 文档图像 next to the Word file field, and then browse to the Files folder and select the file PerformanceReviewDoc_template.docx.

      • Clear the Save changes check box. This ensures that the template file is not saved with the data added for each employee.

        您已表明将使用文件 PerformanceReviewDoc_template.docx。

        文档图像

  4. 将包含员工数据的 Excel 文件中的信息添加到 Word 文件中。
    1. Click Add Activity 文档图像 inside Use Word File, and then find the Replace Text activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    2. 在“替换文本”活动中:
      • Click Plus 文档图像 on the right side of the Search for field, and then select Text. In the Text Builder, enter <>.

      • Click Plus docs image on the right side of the Replace with field, and then select Employee > Full Name.

        You have indicated that you want to replace the placeholder text <> in the Word file with the full name that is copied for each employee from the cell in the Full Name column of the Employees Excel file.

    3. Click Add Activity 文档图像 below the Replace Text activity, and then find the Set Bookmark Content activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    4. 在“设置书签内容”活动中:
      • Click Plus 文档图像 on the right side of the Bookmark name field, and then select Text. In the Text Builder, enter DirectManager.

      • Click Plus docs image on the right side of the Bookmark text field, and then select Employee > Direct Manager.

        您已经表明,针对每位员工,您希望复制 Employees Excel 文件“直接经理”列中单元格的内容并将其粘贴到 Word 文件中 DirectManager 书签的位置,以便将直接经理的姓名添加到 Word 文件。

    5. 重复步骤 3-4 三次,以添加其他“设置书签内容”活动,这些活动会将每个员工的全名、位置和职务添加到 Word 文件中。按如下方式配置每个活动:
      • 书签名称 FullName,书签文本 员工 > 全名

      • 书签名称 Location,书签文本 员工 > 位置

      • 书签名称 PositionTitle,书签文本 员工 > 职务

        文档图像

  5. 将包含项目相关数据的 Excel 文件中的信息添加到 Word 文件中。
    1. Click Add Activity 文档图像 below the last Set Bookmark Content, and then find the Use Excel File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    2. 在“使用 Excel 文件”活动中:
      • Click Plus docs image on the right side of the Excel file field, and then select Text.

        在文本生成器中:

        1. 输入文本 Files\

        2. Click Plus 文档图像 on the right side of the Text Builder, and then select Employee > Full Name.

        3. 输入文本 _Projects.xlsx

          文本应如下所示:Files\[Employee]FullName_Projects.xlsx

        4. Click Save in the Text Builder.

          您已经表明,针对每位员工,您希望将项目 Excel 文件添加到自动化中。因为 Excel 文件的选择是一个动态的文件路径,并且您希望能够在使用项目文件的活动中选择数据,所以您将其中一个文件指定为模板文件。

    3. Click Add Activity 文档图像 inside the newly added Use Excel File activity, and then find the Insert DataTable in Document activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    4. 在“在文档中插入数据表”活动中:
      • Click Plus 文档图像 on the right side of the Table to insert field, and then select Projects > Sheet1 [Sheet] > Table1 [Table].

      • 从“相对插入”下拉菜单中,选择“书签”

      • Click Plus 文档图像 on the right side of the Bookmark to search for field, and then select Text. In the Text Builder, enter Projects.

      • 从“插入位置”下拉菜单中,选择“之后”

        您已经表明,针对每个员工,您希望从 Projects Excel 文件中复制 Table1 并将其粘贴到 Word 文件中名为 Projects 的书签后。

        文档图像

  6. 将文本文件中包含经理反馈的信息添加到 Word 文件中,并为每个员工保存一个单独的文件。
    1. Click Add Activity 文档图像 below the newly added Use Excel File activity, and then find the Read Text File activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    2. 在“读取文本文件”活动中:
      • Click Plus docs image on the right side of the Filename field, and then select Text.

        在文本生成器中:

        1. 输入文本 Files\

        2. Click Plus 文档图像 on the right side of the Text Builder, and then select Employee > Full Name.

        3. 输入文本 _ManagerFeedback.txt

          文本应如下所示:Files\[Employee]FullName_ManagerFeedback.txt

        4. Click Save in the Text Builder.

      • In the Properties panel, click Plus 文档图像 on the right side of the Output to field, and then select Open in Advanced Editor. Enter the expression Saved.Values(Of String)("ManagerFeedback") and click OK.

        您已经表明,针对每个员工,您希望从文件名中包含员工姓名的文本文件中复制经理反馈,并且您想要保存该反馈以供以后在自动化中使用。

    3. Click Add Activity 文档图像 below the Read Text File activity, and then find the Set Bookmark Content activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    4. 在“设置书签内容”活动中:
      • Click Plus 文档图像 on the right side of the Bookmark name field, and then select Text. In the Text Builder, enter DirectManagerFeedback.

      • Click Plus docs image on the right side of the Bookmark text field, and then select Use Saved Value > ManagerFeedback.

        您已表明,针对每位员工,您希望复制您在“读取文本文件”活动中保存以备后用的经理反馈,并将其粘贴到 Word 文件中 DirectManagerFeedback 书签的位置。

        文档图像

    5. Click Add Activity 文档图像 below the Set Bookmark Content activity, and then find the Save Word File As activity in the search box at the top of the screen and select it. The activity is added to the Designer panel.
    6. 在“将 Word 文件另存为”活动中。
      • Click Plus docs image on the right side of the Save as file field, and then select Text.

        在文本生成器中:

        1. 输入文本 Output\

        2. Click Plus 文档图像 on the right side of the Text Builder, and then select Employee > Full Name.

        3. 输入文本 _PerformanceReview.docx

          文本应如下所示:Output\[Employee]FullName_PerformanceReview.docx

        4. Click Save in the Text Builder.

      • 保留其他选项的默认选择。

        您已表明要将用每个员工的数据修改后的模板文件保存到名为 Output 的新文件夹中。每个员工的全名将添加到使用 Employee Excel 文件“全名”列中值的文件名中。

    7. Click Save in the StudioX ribbon to save the automation, then click Run to execute the automation.The automation creates separate performance review Word documents for each employee in the Output folder and populates the files with information from the Excel files with employee data and projects information, and from the text files with manager feedback. Download example

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新