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

生产力活动

上次更新日期 2026年1月15日

管理 Word 文档

下面的示例说明了如何通过读取文件中的文本、在消息框中显示文本、附加文本以及无需打开 Microsoft Word 即可替换文本来自定义 Word 文档。该示例使用“读取文本”“附加文本”“替换文档中的文本”等活动。您可以在“UiPath.Word.Activities”包中找到这些活动。

此自动化流程的构建方法如下:

  1. 打开 Studio ,创建一个新“流程”

  2. Download and extract the archive with the project in this example and copy the file document.docx to your project folder.

  3. 将“序列”容器拖动至“工作流设计器”

    • 创建以下变量:

      变量名称变量类型默认值
      text字符串不适用
  4. Drag a Message Box activity inside the Sequence container.

    • 在“文本”字段中添加表达式 "This is the original document."
  5. Drag a Read Text activity below the Message Box activity.

    • Add the expression "document.docx" in the File path field.
    • 在“文本”字段中添加“text”变量。
  6. Drag a Message Box below the Read Text activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • 在“文本”字段中添加“text”变量。
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  7. Drag a Message Box below the previous Message Box activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • 在“文本”字段中添加表达式 "A new paragraph is added"
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  8. Drag an Append Text activity below the Message Box activity.

    • Add the expression "document.docx" in the File path field.
    • Add the following expression in the Text field: "Nulla eu arcu a urna ultrices scelerisque nec in lectus. Suspendisse iaculis cursus turpis. Sed sed nibh in augue molestie egestas sit amet ac justo. Suspendisse facilisis, mi scelerisque mattis elementum, leo nisi euismod turpis, sed consequat nibh nulla non ipsum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mauris risus, aliquam vel tristique blandit, consectetur ac nunc. Phasellus convallis dolor ligula, non auctor nulla lobortis sit amet. Nulla eu lectus fermentum, porttitor metus in, consectetur ex. Vivamus gravida justo et auctor fermentum. Cras nisl urna, blandit et elementum sit amet, sodales ut tellus. In sit amet semper lectus. Donec ac ipsum vel libero mattis porta vitae id velit. Nullam facilisis porttitor elementum. Ut congue tristique nisi, ornare porta enim mattis eu. Donec in lacus risus. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.".
    • Select the check box for the New line option.
  9. Drag a Read Text activity below the Append Text activity.

    • Add the expression "document.docx" in the File path field.
    • 在“文本”字段中添加“text”变量。
  10. Drag a Message Box below the Read Text activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • 在“文本”字段中添加“text”值。
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  11. Drag a Message Box below the previous Message Box activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • 在“文本”字段中添加“"Replace all the occurrences of the word "lorem" with "REPLACED""”值。
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  12. Drag a Replace Text activity below the Message Box activity.

    • Add the expression "document.docx" in the File path field.
    • Add the value "REPLACED" in the Replace field.
    • Add the value "lorem" in the Search field.
  13. Drag a Read Text activity below the Replace Text activity.

    • Add the expression "document.docx" in the File path field.
    • 在“文本”字段中添加“text”变量。
  14. Drag a Message Box activity below the Read Text activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.
    • 在“文本”字段中添加“text”值。
    • Select the check box for the TopMost option. This always brings the message box to the foreground.
  15. Drag a Message Box activity below the previous Message Box activity.

    • In the Properties panel, select the Ok option from the Buttons drop-down list.

    • 在“文本”字段中添加“"This activity doesn't need to open Word to interact with it. Thank you and goodbye!"”值。

    • Select the check box for the TopMost option. This always brings the message box to the foreground.

    • 您的工作流应如下所示:

      docs image

  16. 运行流程。 多个消息框显示文档的原始文本、包含已添加段落的文本以及包含已替换单词的文本。

此页面有帮助吗?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath Logo
信任与安全
© 2005-2026 UiPath。保留所有权利。