Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

RPA.Tables

Append a column to a table.

Arguments

ArgumentTypeDefault value
tableTablenull
namestr, NoneNone
valuesAny, NoneNone
param table:Table to modify
param name:Name of new column
param values:Value(s) for new column

The values can either be a list of values, one for each row, or one single value that is set for all rows.

Examples:

# Add empty column Add table column ${table} # Add empty column with name Add table column ${table} name=Home Address # Add new column where every every row has the same value Add table column ${table} name=TOS values=${FALSE} # Add new column where every row has a unique value ${is_first}= Create list ${TRUE} ${FALSE} ${FALSE} Add table column ${table} name=IsFirst values=${is_first}

Append rows to a table.

Arguments

ArgumentTypeDefault value
tableTablenull
valuesAny, NoneNone
param table:Table to modify
param values:Value(s) for new row

The values can either be a list of values, or a dictionary where the keys match current column names. Values for unknown keys are discarded.

It can also be a single value that is set for all columns, which is None by default.

Examples:

# Add empty row Add table row ${table} # Add row where every column has the same value Add table row ${table} Unknown # Add values per column ${values}= Create dictionary Username=Mark Mail=mark@robocorp.com Add table row ${table} ${values}

Clear table in-place, but keep columns.

Arguments

ArgumentTypeDefault value
tableTablenull
param table:Table to clear

Usage

Clear table ${table}

Make a copy of a table object.

Arguments

ArgumentTypeDefault value
tableTablenull
param table:Table to copy
return:Table object

${table_copy}= Copy table ${table}

Create Table object from data.

Arguments

ArgumentTypeDefault value
dataDict[int | str, Dict | List | Tuple | NamedTuple | set], List[Dict | List | Tuple | NamedTuple | set], Table, NoneNone
trimboolFalse
columnsList[str], NoneNone

Data can be a combination of various iterable containers, e.g. list of lists, list of dicts, dict of lists.

param data:Source data for table
param trim:Remove all empty rows from the end of the worksheet, default False
param columns:Names of columns (optional)
return:Table object

See the main library documentation for more information about supported data types.

Usage

# Create a new table using a Dictionary of Lists @{Table_Data_name}= Create List Mark John Amy @{Table_Data_age}= Create List ${58} ${22} ${67} &{Table_Data}= Create Dictionary ... name=${Table_Data_name} ... age=${Table_Data_age} ${table}= Create Table ${Table_Data}

Convert a table object into standard Python containers.

Arguments

ArgumentTypeDefault value
tableTablenull
with_indexboolFalse
as_listboolTrue
param table:Table to convert to dict
param with_index:Include index in values
param as_list:Export data as list instead of dict
return:A List or Dictionary that represents the table

Usage

${orders}= Read worksheet as table orders.xlsx Sort table by column ${orders} CustomerId ${export}= Export table ${orders} # The following keyword expects a dictionary: Write as JSON ${export}

Remove all rows from a table which have only None values.

Arguments

ArgumentTypeDefault value
tableTablenull
param table:Table to filter

The filtering will be done in-place.

Usage

Filter empty rows ${table}

Remove all rows where column values don't match the given condition.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
operatorstrnull
valueAnynull
param table:Table to filter
param column:Column to filter with
param operator:Filtering operator, e.g. >, <, ==, contains
param value:Value to compare column to (using operator)

See the keyword Find table rows for all supported operators and their descriptions.

The filtering will be done in-place.

Examples:

# Only accept prices that are non-zero Filter table by column ${table} price != ${0} # Remove uwnanted product types @{types}= Create list Unknown Removed Filter table by column ${table} product_type not in ${types}

Run a keyword for each row of a table, then remove all rows where the called keyword returns a falsy value.

Arguments

ArgumentTypeDefault value
tableTablenull
namestrnull
argsnull

Can be used to create custom RF keyword based filters.

param table:Table to modify.
param name:Keyword name used as filter.
param args:Additional keyword arguments to be passed. (optional)

The row object will be given as the first argument to the filtering keyword.

Find all the rows in a table which match a condition for a given column.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
operatorstrnull
valueAnynull
param table:Table to search into.
param column:Name or position of the column to compare with.
param operator:Comparison operator used with every cell value on the specified column.
param value:Value to compare against.
return:New Table object containing all the rows matching the condition.

Supported operators:

OperatorDescription
>Cell value is larger than
<Cell value is smaller than
>=Cell value is larger or equal than
<=Cell value is smaller or equal than
==Cell value is equal to
!=Cell value is not equal to
isCell value is the same object
not isCell value is not the same object
containsCell value contains given value
not containsCell value does not contain given value
inCell value is in given value
not inCell value is not in given value

Returns the matches as a new Table instance.

Examples:

# Find all rows where price is over 200 @{rows} = Find table rows ${table} Price > ${200} # Find all rows where the status does not contain "removed" @{rows} = Find table rows ${table} Status not contains removed

Get a cell value from a table.

Arguments

ArgumentTypeDefault value
tableTablenull
rowint, strnull
columnint, strnull
param table:Table to read from
param row:Row of cell
param column:Column of cell
return:Cell value

Examples:

# Get the value in the first row and first column Get table cell ${table} 0 0 # Get the value in the last row and first column Get table cell ${table} -1 0 # Get the value in the last row and last column Get table cell ${table} -1 -1 # Get the value in the third row and column "Name" Get table cell ${table} 2 Name

Get all values for a single column in a table.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
param table:Table to read
param column:Column to read
return:List of the rows in the selected column

Usage

${emails}= Get table column ${users} E-Mail Address

Return table dimensions, as (rows, columns).

Arguments

ArgumentTypeDefault value
tableTablenull
param table:Table to inspect
return:Two integer values that represent the number of rows and columns

Usage

${rows} ${columns}= Get table dimensions ${table} Log Table has ${rows} rows and ${columns} columns.

Get a single row from a table.

Arguments

ArgumentTypeDefault value
tableTablenull
rowint, strnull
as_listboolFalse
param table:Table to read
param row:Row to read
param as_list:Return list instead of dictionary
return:Dictionary or List of table row

Examples:

# returns the first row in the table ${first}= Get table row ${orders} # returns the last row in the table ${last}= Get table row ${orders} -1 as_list=${TRUE}

Return a new Table from a range of given Table rows.

Arguments

ArgumentTypeDefault value
tableTablenull
startstr, int, NoneNone
endstr, int, NoneNone
param table:Table to read from
param start:Start index (inclusive)
param start:End index (exclusive)
return:Table object of the selected rows

If start is not defined, starts from the first row. If end is not defined, stops at the last row.

Examples:

# Get all rows except first five ${slice}= Get table slice ${table} start=5 # Get rows at indexes 5, 6, 7, 8, and 9 ${slice}= Get table slice ${table} start=5 end=10 # Get all rows except last five ${slice}= Get table slice ${table} end=-5

Group a table by column and return a list of grouped Tables.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
param table:Table to use for grouping
param column:Column which is used as grouping criteria
return:List of Table objects

Usage

# Groups rows of matching customers from the customer column @{groups}= Group table by column ${orders} customer # An example of how to use the List of Tables once returned FOR ${group} IN @{groups} # Process all orders for the customer at once Process order ${group} END

Run a keyword for each cell in a given column, and replace its content with the return value.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
namestrnull
argsnull

Can be used to easily convert column types or values in-place.

param table:Table to modify.
param column:Column to modify.
param name:Mapping keyword name.
param args:Additional keyword arguments. (optional)

The cell value will be given as the first argument to the mapping keyword.

Examples:

# Convert all columns values to a different type Map column values ${table} Price Convert to integer # Look up values with a custom keyword Map column values ${table} User Map user ID to name

Create a union of two tables and their contents.

Arguments

ArgumentTypeDefault value
tablesTablenull
indexstr, NoneNone
param tables:Tables to merge
param index:Column name to use as index for merge
return:Table object

By default rows from all tables are appended one after the other. Optionally a column name can be given with index, which is used to merge rows together.

Usage

For instance, a name column could be used to identify unique rows and the merge operation should overwrite values instead of appending multiple copies of the same name.

NamePrice
Egg10.0
Cheese15.0
Ham20.0
NameStock
Egg12.0
Cheese99.0
Ham0.0
${products}= Merge tables ${prices} ${stock} index=Name FOR ${product} IN @{products} Log many ... Product: ${product}[Name] ... Price: ${product}[Price] ... Stock: ${product}[Stock] END

Remove column from table and return it.

Arguments

ArgumentTypeDefault value
tableTablenull
columnstr, int, NoneNone
param table:Table to modify
param column:Column to remove
return:Dictionary or List of the removed, popped, column

Examples:

# Remove column from table and discard it Pop table column ${users} userId # Remove column from table and iterate over it ${ids}= Pop table column ${users} userId FOR ${id} IN @{ids} Log User id: ${id} END

Remove row from table and return it.

Arguments

ArgumentTypeDefault value
tableTablenull
rowstr, int, NoneNone
as_listboolFalse
param table:Table to modify
param row:Row index, pops first row if none given
param as_list:Return list instead of dictionary
return:Dictionary or List of the removed, popped, row

Examples:

# Pop the firt row in the table and discard it Pop table row ${orders} # Pop the last row in the table and store it ${row}= Pop table row ${data} -1 as_list=${TRUE}

Read a CSV file as a table.

Arguments

ArgumentTypeDefault value
pathstrnull
headerbool, NoneNone
columnsList[str], NoneNone
dialectstr, Dialect, NoneNone
delimitersstr, NoneNone
column_unknownstrUnknown
encodingstr, NoneNone
param path:Path to CSV file
param header:CSV file includes header
param columns:Names of columns in resulting table
param dialect:Format of CSV file
param delimiters:String of possible delimiters
param column_unknown:Column name for unknown fields
param encoding:Text encoding for input file, uses system encoding by default
return:Table object

By default attempts to deduce the CSV format and headers from a sample of the input file. If it's unable to determine the format automatically, the dialect and header will have to be defined manually.

Builtin dialect values are excel, excel-tab, and unix, and header is boolean argument (True/False). Optionally a set of valid delimiters can be given as a string.

The columns argument can be used to override the names of columns in the resulting table. The amount of columns must match the input data.

If the source data has a header and rows have more fields than the header defines, the remaining values are put into the column given by column_unknown. By default it has the value "Unknown".

Examples:

# Source dialect is deduced automatically ${table}= Read table from CSV export.csv Log Found columns: ${table.columns} # Source dialect is known and given explicitly ${table}= Read table from CSV export-excel.csv dialect=excel Log Found columns: ${table.columns}

Renames columns in the Table with given values. Columns with name as None will use the previous value.

Arguments

ArgumentTypeDefault value
tableTablenull
namesList[str | None]null
strictboolFalse
param table:Table to modify
param names:List of new column names
param strict:If True, raises ValueError if column lengths do not match

The renaming will be done in-place.

Examples:

# Initially set the column names ${columns}= Create list First Second Third Rename table columns ${table} ${columns} # First, Second, Third # Update the first and second column names to Uno and Dos ${columns}= Create list Uno Dos Rename table columns ${table} ${columns} # Uno, Dos, Third

Set existing row as names for columns.

Arguments

ArgumentTypeDefault value
tableTablenull
rowint, strnull
param table:Table to modify
param row:Row to use as column names

Usage

# Set the column names based on the first row Set row as column names ${table} 0

Set a cell value in a table.

Arguments

ArgumentTypeDefault value
tableTablenull
rowint, strnull
columnint, strnull
valueAnynull
param table:Table to modify to
param row:Row of cell
param column:Column of cell
param value:Value to set

Examples:

# Set the value in the first row and first column to "First" Set table cell ${table} 0 0 First # Set the value in the last row and first column to "Last" Set table cell ${table} -1 0 Last # Set the value in the last row and last column to "Corner" Set table cell ${table} -1 -1 Corner # Set the value in the third row and column "Name" to "Unknown" Set table cell ${table} 2 Name Unknown

Assign values to a column in the table.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
valuesAnynull
param table:Table to modify
param column:Column to modify
param values:Value(s) to set

The values can either be a list of values, one for each row, or one single value that is set for all rows.

Examples:

# Set different value for each row (sizes must match) ${ids}= Create list 1 2 3 4 5 Set table column ${users} userId ${ids} # Set the same value for all rows Set table column ${users} email ${NONE}

Assign values to a row in the table.

Arguments

ArgumentTypeDefault value
tableTablenull
rowint, strnull
valuesAnynull
param table:Table to modify
param row:Row to modify
param values:Value(s) to set

The values can either be a list of values, or a dictionary where the keys match current column names. Values for unknown keys are discarded.

It can also be a single value that is set for all columns.

Examples:

${columns}= Create list One Two Three ${table}= Create table columns=${columns} ${values}= Create list 1 2 3 Set table row ${table} 0 ${values} ${values}= Create dictionary One=1 Two=2 Three=3 Set table row ${table} 1 ${values} Set table row ${table} 2 ${NONE}

Sort a table in-place according to column.

Arguments

ArgumentTypeDefault value
tableTablenull
columnint, strnull
ascendingboolTrue
param table:Table to sort
param column:Column to sort with
param ascending:Table sort order

Examples:

# Sorts the order_date column ascending Sort table by column ${orders} order_date # Sorts the order_date column descending Sort table by column ${orders} order_date ascending=${FALSE}

Return first count rows from a table.

Arguments

ArgumentTypeDefault value
tableTablenull
countint5
as_listboolFalse
param table:Table to read from
param count:Number of lines to read
param as_list:Return list instead of Table
return:Return Table object or List of the selected rows

Usage

# Get the first 10 employees ${first}= Table head ${employees} 10

Return last count rows from a table.

Arguments

ArgumentTypeDefault value
tableTablenull
countint5
as_listboolFalse
param table:Table to read from
param count:Number of lines to read
param as_list:Return list instead of Table
return:Return Table object or List of the selected rows

Usage

# Get the last 10 orders ${latest}= Table tail ${orders} 10

Remove all extraneous whitespace from column names.

Arguments

ArgumentTypeDefault value
tableTablenull
param table:Table to filter

The filtering will be done in-place.

Usage

# This example will take colums such as: Trim column names ${table}

Remove all rows from the end of a table which have only None as values.

Arguments

ArgumentTypeDefault value
tableTablenull
param table:Table to filter

The filtering will be done in-place.

Usage

Trim empty rows ${table}

Write a table as a CSV file.

Arguments

ArgumentTypeDefault value
tableTablenull
pathstrnull
headerboolTrue
dialectstr, DialectExcel
encodingstr, NoneNone
delimiterstr, None,
param table:Table to write
param path:Path to write to
param header:Write columns as header to CSV file
param dialect:The format of output CSV
param encoding:Text encoding for output file, uses system encoding by default
param delimiter:Delimiter character between columns

Builtin dialect values are excel, excel-tab, and unix.

Usage

${sheet}= Read worksheet as table orders.xlsx header=${TRUE} Write table to CSV ${sheet} output.csv