Get Office Value
Gets the value of an existing location in an Office file.
Command availability: IBM RPA SaaS and IBM RPA on premises
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
officeGet --location(String) [--firstrowhasheaders(Boolean)] --officeapplication(OfficeApplication) (String)=text (Boolean)=boolean (Numeric)=numeric (DataTable)=datatable (List<String>)=stringlist (DateTime)=datetime
Dependencies
-
To use this command, open an Office file with the Open Office file (
officeOpen
) command. -
Microsoft™ Office 2010 or higher is required.
-
Ensure that the architecture (bitness) of your Office apps, IBM RPA, and your operating system match. For example, if you are using a 64-bit operating system, IBM RPA and Office must be 64-bit too.
Input parameters
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Location | location |
Required |
Text |
Location of the Office file where the value is taken from. See the location parameter for more details. |
Has Headers | firstrowhasheaders |
Optional |
Boolean |
Enable to use the worksheet's first line as a header. ❕ Important: This parameter is used when the Office application is an Excel file. |
Office Application | officeapplication |
Required |
Office Application |
Variable that stores the Office Application instance. |
location
parameter
The location
parameter accepts a string that specifies the location from which to extract data. The format of this string varies depending on the type of Office file that you are working with.
- Word files
Enter the page numbers that you want to extract data from, separated by semicolons. For example, if you want to extract data from pages 1, 2, and 3, type in: 1;2;3.
- PowerPoint files
Enter the slide number followed by a semicolon, then the object index that you want to extract data from. For example, if you want to extract data from object 2 on slide 1, type in: 1;2. The command searches following the index order of objects contained in the slide.
You can also do: slideNumber;objectType[objectIndex]
, for example: 1;Textbox[1]. All index values start at 1.
- Excel files
Enter the name of the sheet followed by a space, then the cell reference that you want to extract data from. For example, if you want to extract the value from cell A5 in a sheet named "stockTable", type in: stockTable A5.
Output parameters
Designer mode label | Script mode name | Accepted variable types | Description |
---|---|---|---|
Text | text | Text |
Text that is obtained from the file according to Location . |
Boolean | boolean |
Boolean |
Boolean obtained from the file according to Location . |
Number | numeric |
Number |
Number that is obtained from the file according to Location . |
Data Table | datatable |
Data Table |
Data table that is obtained from the file according to Location . |
List | stringlist |
List<Text> |
List that is obtained from the file according to Location . |
Date | datetime |
Date Time |
Date that is obtained from the file according to Location . |
Example
The following code example demonstrates how to get a value from an excel file. The Open Office File (officeOpen
) command opens the Excel file and stores its instance
in the officeApplication variable. The Get Office Value command uses this variable to obtain the text from Location
Sheet1 A1 and the Boolean value from Location
Sheet1 A6.
defVar --name officeApplication --type OfficeApplication
defVar --name obtainedText --type String
defVar --name boolean --type Boolean
officeOpen --path "Path of the sample file" --type "Excel" --keepvisibleofficeApplication=officeapplication
officeGet --location "location to get value from" --officeapplication ${officeApplication} obtainedText=text
officeGet --location "location to get value from" --officeapplication ${officeApplication} boolean=boolean
officeSave --fileformat "Default" --officeapplication ${officeApplication}
officeClose --officeapplication ${officeApplication}
logMessage --message " Text: ${obtainedText}\r\nboolean: ${boolean}" --type "Info"
❕ Important: To use the sample script, use a sample file and enter its path in the File Path
parameter of the Open Office File command.