Python API
Excel.Application
- class RPA.Word.Application.Application
Bases:
object
Word.Application is a library for controlling a Word application.
Note. Library works only Windows platform.
Examples
Robot Framework
*** Settings *** Library RPA.Word.Application Task Setup Open Application Suite Teardown Quit Application *** Tasks *** Open existing file Open File old.docx Write Text Extra Line Text Write Text Another Extra Line of Text Save Document AS ${CURDIR}${/}new.docx ${texts}= Get all Texts Close Document
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()
- ROBOT_LIBRARY_DOC_FORMAT = 'REST'
- ROBOT_LIBRARY_SCOPE = 'GLOBAL'
- close_document(save_changes: bool = False) None
Close the active document (if open).
- create_new_document() None
Create new document for Word application
- export_to_pdf(filename: str) None
Export active document into PDF file.
- Parameters
filename – PDF to export WORD into
- get_all_texts() str
Get all texts from active document
- Returns
texts
- open_application(visible: bool = False, display_alerts: bool = False) None
Open the Word application.
- Parameters
visible – show window after opening
display_alerts – show alert popups
- open_file(filename: str, read_only: bool = True) None
Open Word document with filename.
- Parameters
filename – Word document path
- quit_application(save_changes: bool = False) None
Quit the application.
- replace_text(find: str, replace: str) None
Replace text in active document
- Parameters
find – text to replace
replace – new text
- save_document() None
Save active document
- save_document_as(filename: str, fileformat: Optional[str] = None) 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
Set footer for the active document
- Parameters
text – footer text to set
- set_header(text: str) None
Set header for the active document
- Parameters
text – header text to set
- write_text(text: str, newline: bool = True) None
Writes given text at the end of the document
- Parameters
text – string to write
newline – write text to newline if True, default to True