RPA.Excel.Application
module RPA.Excel.Application
class RPA.Excel.Application.Application
Excel.Application is a library for controlling the Excel 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 ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
method add_new_sheet
Add new worksheet to workbook. Workbook is created by default if it does not exist.
Parameters
- sheetname β name for sheet
- create_workbook β create workbook if True, defaults to True
- Raises: ValueError β error is raised if workbook does not exist and create_workbook is False
method add_new_workbook
Adds new workbook for Excel application
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 export_as_pdf
Export Excel as PDF file
If Excel filename is not given, the currently open workbook will be exported as PDF.
Parameters
- pdf_filename β PDF filename to save
- excel_filename β Excel filename to open
method find_first_available_cell
Find first available free cell
Parameters
- worksheet β worksheet to handle, defaults to active worksheet if None
- row β starting row for search, defaults to 1
- column β starting column for search, defaults to 1
- Returns: tuple (row, column) or (None, None) if not found
method find_first_available_row
Find first available free row
Parameters
- worksheet β worksheet to handle, defaults to active worksheet if None
- row β starting row for search, defaults to 1
- column β starting column for search, defaults to 1
- Returns: row or None
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_workbook
Open Excel by filename
By default sets active worksheet to sheet number 1
- Parameters: filename β path to filename
method quit_application
Quit the application.
- Parameters: save_changes β Enable to save changes on quit. (False by default)
method read_from_cells
Read value from cell.
Parameters
- worksheet β worksheet to handle, defaults to active worksheet if None
- row β target row, defaults to None
- column β target row, defaults to None
- Raises: ValueError β if cell is not given
method run_macro
Run Excel macro with given name
Parameters
- macro_name β macro to run
- args β arguments to pass to macro
method save_excel
Saves Excel file
method save_excel_as
Save Excel with name if workbook is open
Parameters
- filename β where to save file
- autofit β autofit cell widths if True, defaults to False
- file_format β format of file
Note: Changing the file extension for the path does not
affect the actual format. To use an older format, use
the file_format
argument with one of the following values:
https://docs.microsoft.com/en-us/office/vba/api/excel.xlfileformat
method set_active_worksheet
Set active worksheet by either its sheet number or name
Parameters
- sheetname β name of Excel sheet, defaults to None
- sheetnumber β index of Excel sheet, defaults to None
method write_to_cells
Write value, number_format and/or formula into cell.
Parameters
- worksheet β worksheet to handle, defaults to active worksheet if None
- row β target row, defaults to None
- column β target row, defaults to None
- value β possible value to set, defaults to None
- number_format β possible number format to set, defaults to None
- formula β possible format to set, defaults to None
- Raises: ValueError β if cell is not given