RPA.Word.Application

module RPA.Excel.Application

class RPA.Word.Application.Application

Application(autoexit: bool = True)

Word.Application is a library for controlling the Word application.

Examples

Robot Framework

Python

from RPA.Word.Application import Application app = Application() app.open_application() app.open_file('old.docx') app.write_text('Extra Line Text') app.save_document_as('new.docx') app.quit_application()

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:


variable APP_DISPATCH

APP_DISPATCH = 'Word.Application'

variable FILEFORMATS

FILEFORMATS = {'DEFAULT': 'wdFormatDocumentDefault', 'HTML': 'wdFormatHTML', 'OPENDOCUMENT': 'wdFormatOpenDocumentText', 'PDF': 'wdFormatPDF', 'RTF': 'wdFormatRTF', 'WORD97': 'wdFormatDocument97'}

variable ROBOT_LIBRARY_DOC_FORMAT

ROBOT_LIBRARY_DOC_FORMAT = 'REST'

variable ROBOT_LIBRARY_SCOPE

ROBOT_LIBRARY_SCOPE = 'GLOBAL'

property app

property app

method close_document

close_document(save_changes: bool = False)

Close the active document and app (if open).

  • Parameters: save_changes – Enable changes saving on quit. (False by default)

method create_new_document

create_new_document()

Create new document for Word application


method export_to_pdf

export_to_pdf(filename: str)

Export active document into PDF file.

  • Parameters: filename – PDF to export WORD into

method get_all_texts

get_all_texts()

Get all texts from active document

  • Returns: texts

method open_application

open_application(visible: bool = False, display_alerts: bool = False)

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_file(filename: str, read_only: bool = True)

Open Word document with filename.

  • Parameters: filename – Word document path

method quit_application

quit_application(save_changes: bool = False)

Quit the application.

  • Parameters: save_changes – Enable to save changes on quit. (False by default)

method replace_text

replace_text(find: str, replace: str)

Replace text in active document

Parameters
  • find – text to replace
  • replace – new text

method save_document

save_document()

Save active document


method save_document_as

save_document_as(filename: str, fileformat: Optional[str] = None)

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 set_footer

set_footer(text: str)

Set footer for the active document

  • Parameters: text – footer text to set

method set_header

set_header(text: str)

Set header for the active document

  • Parameters: text – header text to set

method write_text

write_text(text: str, newline: bool = True)

Writes given text at the end of the document

Parameters
  • text – string to write
  • newline – write text to newline if True, default to True