RPA.Word.Application
module RPA.Excel.Application
class RPA.Word.Application.Application
Word.Application is a library for controlling the Word application.
Examples
Robot Framework
Python
Caveats
This library works on a Windows operating system with UI enabled only, and you must
ensure that you open the app first with Open Application
before running any
other relevant keyword which requires to operate on an open app. The application is
automatically closed at the end of the task execution, so this can be changed by
importing the library with the autoexit=${False} setting.
If you’re running the Process by Control Room through a custom self-hosted Worker service, then please make sure that you enable an RDP session by ticking “Use Desktop Connection” under the Step configuration.
If you still encounter issues with opening a document, please ensure that file can be opened first manually and dismiss any alert potentially blocking the process.
Check the documentation below for more info:
- https://robocorp.com/docs/control-room/unattended/worker-setups/windows-desktop
- https://robocorp.com/docs/faq/windows-server-2016
variable APP_DISPATCH
variable FILEFORMATS
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
property app
method close_document
Close the active document and app (if open).
- Parameters: save_changes – Enable changes saving on quit. (False by default)
method copy_selection_to_clipboard
Copy current text selection to clipboard.
method create_new_document
Create new document for Word application
method export_to_pdf
Export active document into PDF file.
- Parameters: filename – PDF to export WORD into
method find_text
Find text in the document.
Parameters
- text – text to find
- cursor_position – where to move cursor after finding text
- copy – copy found text into clipboard
- Raises: AssertionError – if text is not found
method get_all_texts
Get all texts from active document
- Returns: texts
method get_current_line
Get the text of the current line in the document.
method get_number_of_lines
Get the number of lines in the document.
method move_horizontally
Move cursor horizontally from current cursor position.
Remember that if cursor is already at the start the cursor can’t move left and if cursor is already at the end the cursor can’t move right.
- Parameters: characters – characters to move
method move_to_end
Move cursor to the end of the document.
method move_to_line_end
Move cursor to end of the line on the current cursor position.
method move_to_line_start
Move cursor to start of the line on the current cursor position.
method move_to_top
Move cursor to the top of the document.
method move_vertically
Move cursor vertically from current cursor position.
Remember that if cursor is already at the top the cursor can’t move up and if cursor is already at the bottom the cursor can’t move down.
- Parameters: lines – lines to move
method open_application
Open the application.
Parameters
- visible – Show the window on opening. (False by default)
- display_alerts – Display alert popups. (False by default)
method open_file
Open Word document with filename.
- Parameters: filename – Word document path
method paste_from_clipboard
Paste content from clipboard to the document’s current cursor position.
method quit_application
Quit the application.
- Parameters: save_changes – Enable to save changes on quit. (False by default)
method replace_text
Replace text in active document
Parameters
- find – text to replace
- replace – new text
method save_document
Save active document
method save_document_as
Save document with filename and optionally with given fileformat
Parameters
- filename – where to save document
- fileformat – see @FILEFORMATS dictionary for possible format, defaults to None
method select_current_paragraph
Select text in current active paragraph.
method select_paragraph
Select paragraph(s) from current cursor position.
Negative count moves cursor up number of paragraphs and positive count moves cursor down number of paragraphs.
- Parameters: count – number of paragraphs to select
method set_footer
Set footer for the active document
- Parameters: text – footer text to set
method set_header
Set header for the active document
- Parameters: text – header text to set
method set_object_property
Set the property of any object.
This is a utility keyword for Robot Framework syntax to set object property values.
Parameters
- object_instance – object instance to set the property
- property_name – property name to set
- value – value to set
method write_text
Writes given text at the end of the document
Parameters
- text – string to write
- cursor_position – where to move cursor before writing
- end_of_text – if True moves cursor to the end of the text before writing