Print Office File

Prints the content of 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.

officePrint [--printtofile(Boolean)] [--collate(Boolean)] --copies(Numeric) --filepath(String) [--selectprinter(Boolean)] --printername(String) [--location(String)] --officeapplication(OfficeApplication) (String)=value


  • 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
Print to File printtofile Optional Boolean Enable to save the content of the Office Application parameter in an ".oxps" or ".oxp" extension file that can be printed later.
Collate Copies collate Optional Boolean Groups the pages of the file when printing.
Copies copies Required when the Print to File parameter is disabled Number Number of copies to be printed.
Path filepath Required when the Print to File parameter is enabled Text Path of the file that is going to receive the print.
Select Printer selectprinter Optional Boolean Defines which printer should be used.
Printer Name printername Required when the Select Printer parameter is enabled Text Name of the printer.
Location location Optional Text Specific locations within the Office file of which the content will be printed.
Office Application officeapplication Required Office Application Variable that stores the Office application instance.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Path value Text Returns the full path to the generated file.
Applicable when the Print to File parameter is enabled.


Example 1: The Print Office File command prints the Location specified "Sheet A1" on the default printer defined in the operating system.

defVar --name officeApplication --type OfficeApplication
// Use a sample file.
officeOpen --path "Samplefile file path.filetype --type "Excel" --keepvisibleofficeApplication=officeapplication
officePrint --copies 1 --location "Sheet1 A1" --officeapplication ${officeApplication}
officeClose --officeapplication ${officeApplication}

Example 2: The Print Office File command saves the Location specified "Sheet1 A1" in the "Desktop" folder in an ".oxps" file, to print later.

defVar --name officeApplication --type OfficeApplication
defVar --name desktopPath --type String
defVar --name savedFilePath --type String
// Use a sample file.
getSpecialFolder --folder "Desktop" desktopPath=value
officeOpen --path "samplefile.filepath" --type "Excel" --keepvisibleofficeApplication=officeapplication
officePrint --printtofile--filepath "${desktopPath}" --location "Sheet1 A1" --officeapplication ${officeApplication} savedFilePath=value
officeClose --officeapplication ${officeApplication}
logMessage --message "${savedFilePath}" --type "Info"

Important: To run the sample script, create or use a sample file.