
StudioX user guide
Excel 自动化
关于 Excel 自动化
StudioX offers a deep integration with Microsoft Excel and ships with a number of activities that automate the tasks you perform in Excel. For information on installing the Excel add-in, see the Studio guide.
You start by adding the Excel file you want to automate as a resource to the automation project, and then add the activities to perform in the file. When configuring the activities that use the file, you can select sheets, tables, named ranges, and named cells directly from the Plus
menu in StudioX. You can also seamlessly switch from StudioX to Excel to indicate the data to use directly from the file.

If you click Indicate in Excel in the Plus
menu when configuring an activity to select data directly from the file, your spreadsheet is opened in Excel and a UiPath tab appears in the Excel ribbon. Select the data you want to use, for example a cell or a range of cells, and then click Confirm in the UiPath tab to confirm the selection.

You can also manually indicate the Excel data to use by selecting the Custom Input option in the Plus
menu. This option enables you to enter cell and range references, table names, or sheet names, which can be useful when you are working with Excel files with dynamic names, or with files that don't exist at design time and no template file is available.

If you want to repeat the same activities for each row in a range, add a For Each Excel Row activity, and then add the activities to repeat inside it.
要了解如何自动化 Excel 任务,请参阅以下教程:
- 教程:创建透视表
- 教程:遍历表中的行
- 教程:比较 Excel 文件和电子邮件对帐错误
- 教程:从自动化电子邮件中提取数据并将其移至桌面应用程序
- 教程:筛选 Excel 的数据
- 教程:设置单元格的格式
- 教程:将文件夹中文件的相关信息添加到 Excel 文件
- 教程:将自己的公式添加到项目笔记本
- 教程:使用来自 Excel 的数据在 Acrobat Reader 中填充 PDF 表单
可以在 StudioX 中进行以下 Excel 活动:
- 使用 Excel 文件
- 附加范围
- 自动填充
- 自动调整范围
- 更改透视表数据源
- 清除工作表/范围/表格
- 创建透视表
- 复制/粘贴范围
- 删除行
- 删除列
- 删除工作表
- 复制工作表
- 导出为 CSV
- 筛选
- 填充范围
- 查找数据的首行/末行
- 查找/替换值
- 格式化为表格
- 对每个 Excel 行
- 对每个 Excel 工作表
- 设置单元格的格式
- 获取 Excel 图表
- 插入列
- 插入图表
- 插入行
- 插入工作表
- 查找
- “匹配”功能
- 保护工作表
- 读取单元格公式
- 读取单元格值
- 读取范围
- 刷新透视表
- 刷新 Excel 数据连接
- 删除重复项
- 重命名工作表
- 运行电子表格宏
- 保存 Excel 文件
- 将 Excel 文件另存为
- 将 Excel 文件保存为 PDF 格式
- 范围排序
- 分列
- 取消保护工作表
- 更新 Excel 图表
- VLookup
- 写入单元格
- 将数据表写入 Excel
There are a couple of different ways of launching and previewing Excel files, both at runtime and at design time. To learn more, see the Project settings.
将 Excel 文件添加到自动化中
将文件添加到自动化的方式决定了项目中的哪些活动可以访问和修改 Excel 文件,以及文件在执行期间保持打开状态的时间。您可以通过两种方式将 Excel 文件添加到自动化中:
- Add a Use Excel File resource activity. Using this option, the data in the file can only be accessed by the activities added inside the resource activity. After all the activities inside Use Excel File are executed, the file is closed. This is useful when the file will be created at runtime (e.g. downloaded or saved from an email attachment) or if the file needs to sent to another location (e.g. uploaded or sent as an email attachment).
- Connect the project to the Excel file from the Data Manager to add it as a project resource. Using this option, you can configure the scope where the file is available and set it to either the entire workflow or only to a certain container activity. By default, the scope is set to the main container (the entire project), which means that it can be accessed and modified by all the activities in the project, and the file remains open until the entire project is executed. If you don't need the Excel resource to be available in the entire project, you can set the scope closer to the activities where it is used. This ensures the file is open only when it's needed, which can speed up execution. For example, you can add all the activities that interact with an Excel file inside a Group container activity and set the scope to the Group container. Connecting the project to an Excel file is useful when the file name and location won't change and the file doesn't need to be used for other purposes such as uploading or sending as an email attachment.
关于项目笔记本
“项目笔记本”是一个 Excel 工作簿,您可以将其用作暂存器,用于保存公式和操作数据。其目的是在项目执行期间用于计算和临时数据存储。默认情况下,完成自动化执行后,不会保存对项目笔记本所做的更改。
The default Project Notebook is a file named Project_Notebook.xlsx that is created by StudioX in the project folder. The file comes with a predefined set of formulas that you can use in any automation project. The formulas are split on several sheets based on the area they apply to. Each sheet contains cells where you can add input data and formulas that manipulate that data. The formulas are in easy to identify named cells that you can select for use in your automations directly from the Plus
menu.
配置项目笔记本
在 StudioX 功能区中选择“笔记本” > “配置笔记本”。您可以配置以下设置:
-
笔记本文件 - 选择另一个 Excel 文件用作项目笔记本。
-
稍后为其命名 - 输入一个名称,活动与之交互时将使用该名称引用项目中的 Excel 文件。默认名称为
Notes。 -
“访问密码”- 如果适用,请输入打开文件所需的密码。
-
“编辑密码”- 如果适用,请输入编辑文件所需的密码。
-
Autosave file - Select this option if you want the file to be saved at the end of the automation. Otherwise, the file is returned to the initial state after project execution. This option is not selected by default. When the option to save changes is disabled, the message Save changes: off is displayed next to the Project Notebook entries in the Plus
menu and in the Data Manager panel.
-
“只读” - 如果要以只读模式打开文件,请选择此选项。如果文件被锁定以进行编辑或具有编辑密码,这使您可以执行数据提取操作。默认情况下未选中此选项。
项目笔记本的公式
The formulas available in the Project Notebook are detailed below. To learn how you can add formulas to the Project Notebook, see Tutorial: Adding Your Own Formulas to the Project Notebook.
日期
在单元格 B4 (Date_Input) 中输入一个基准日期(默认为今天的日期),并在单元格 B6(天)中输入一个天数(默认为 7 天),稍后将其添加到工作表的 B4 单元格中的日期。可以使用以下公式:
- 日期加天数 (DatePlusDays) - 返回单元格 B6 中的天数与单元格 B4 中的输入日期相加得出的日期。
- 日期加工作日天数 (DatePlusWorkingDays) - 返回单元格 B6 中的天数与单元格 B4 中的输入日期相加得出的日期(不含周末)。
- 日期格式 (YYYYMMDD) - 返回单元格 B4 中的输入日期,该日期已转换为 YYYYMMDD 格式的文本。
- 今天 - 返回今天的日期。
- 上周的日期(星期一、星期五、星期日) - 返回上周的星期一 (LastWeekMonday)、星期五 (LastWeekFriday) 和星期日 (LastWeekSunday) 的日期。
- 上个月的日期(第一天和最后一天) - 返回上个月的第一天 (LastMonthStartDate) 和最后一天 (LastMonthEndDate) 的日期。
- 本月的第一个/最后一个工作日 - 返回当月的第一个工作日 (ThisMonthFirstWorkingDay) 和最后一个工作日 (ThisMonthLastWorkingDay) 的日期。
以与语言环境无关的方式将文本转换为日期
在单元格 B18 (DateText) 中输入一个日期,其中包含在数字后插入的年、月和日的日语字符。日期转换为 MM/DD/YYYY 格式,并在单元格 B29 (ReformattedDate) 中返回。
For an example of how you can use the formulas in the Date sheet, see Tutorial: Working with Files and Folders.
文本
在单元格 B4 (Text_Input) 中输入文本。要在单元格 B4 中搜索特定文本,请在单元格 B10(搜索)中输入要搜索的文本。要将搜索到的文本替换为另一文本,请在单元格 B11(替换)中输入替换文本。可以使用以下公式:
- 修剪 - 返回单元格 B4 中的文本,并删除所有多余的空格。
- 长度 - 返回单元格 B4 中文本的字符数。
- 大写字母 - 返回单元格 B4 中的文本,所有字符均转换为大写字母。
- 小写字母 - 返回单元格 B4 中的文本,所有字符均转换为小写字母。
- 结果 - 返回单元格 B4 中的文本,并通过将单元格 B10 中添加的文本替换为单元格 B11 中添加的文本加以修改。
- 包含 - 检查单元格 B10 中添加的文本是否出现在单元格 B4 中的文本中。如果找到该文本,则返回 TRUE,否则返回 FALSE。
- 名字 - 返回单元格 B4 中文本中最后一个空格字符之前的文本。
- 名字 - 返回单元格 B4 中文本中最后一个空格字符之后的文本。
从文本中提取值
要从单元格 B4 至单元格 F5 中添加的文本中提取特定值,请在单元格 D5 中的值左侧和/或在单元格 E5 中的值右侧添加文本。要提取多个值,请使用第 6-9 行同一列中的单元格。您可以在自动化中使用它来从遵循相同模板的文本块中提取变量值。例如,您可以从自动电子邮件通知(之前带有相同的标签)中提取发票编号和金额之类的值。
For an example of how you can use the formulas in the Text sheet, see Tutorial: Extracting Data from Automated Emails and Moving It to a Desktop Application.
数字
在单元格 B4 (Number_Input) 中输入一个数字。可以使用以下公式来操作该数字:
- 清理 (CleanNumber) - 返回在单元格 B4 中添加的数字,并删除所有换行符和不间断空格。
- 整数 - 返回单元格 B4 中数字的整数部分。
- 2 位小数 (TwoDecimals) - 返回在单元格 B4 中添加的带有 2 位小数的数字。
以与语言环境无关的方式将文本转换为数字
在单元格 B11 (NumberText_Input) 中输入一个没有组分隔符或以点 (.) 作为组分隔符并以逗号 (,) 作为十进制分隔符的数字。该数字在单元格 B15 (ReformattedNumber) 中返回,并转换为使用逗号 (,) 作为组分隔符,使用点 (.) 作为十进制分隔符。
文件
在单元格 B6 (FullFileName_Input) 中输入包含文件扩展名的文件完整路径。可以使用以下公式:
- 文件名 (FileName) - 从单元格 B6 中添加的文件路径返回包含扩展名的文件名。
- 文件扩展名 (FileExtension) - 从单元格 B6 中添加的文件路径返回文件扩展名。
- 不带扩展名的文件名 (FileNameNoExtension) - 从单元格 B6 中添加的文件路径返回不带扩展名的文件名。
- 文件夹 (Folder) - 返回文件夹的路径,该文件夹包含路径已添加到单元格 B6 的文件。
- 重新格式化的文件名 (ReformattedFileName) - 返回单元格 B9 和 B10 中以 . (点)分隔的值。结果是带有扩展名的文件名。
For an example of how you can use the formulas in the File sheet, see Tutorial: Saving, Renaming, and Moving Attachments.