Get table Version 2 (Python)
Action group: Office
Description
The action returns cell values from the specified area of the page as a table.
Action icon
Settings of parameters
Property | Description | Type | Filling example | Mandatory field |
Parameters | ||||
Context | Context for working with a document | Robin.OpenTextDo c | Yes | |
Table number | The number of the table in the document. The order starts from 1. The default value is 1 | Robin.Numeric | No | |
Heading | If the value is «true», the table header will be inserted into the document along with its rows. | Robin.Boolean | true | No |
Remove duplicate header | If the value is «true», indexes will be added to the same column names in the header of the resulting table. Numbering starts from 1. | Robin.Boolean | true | No |
Results | ||||
Result | Result table | Robin.DataTable |
Special conditions of use
For the "With Header" parameter:
From excel we get the table:
With this parameter enabled, the log will show "Columns: 3; rows: 2" because the first row of the taken area has become a header with the column names ‘No.’, ‘Title’, and ‘Tests’. These headers cannot be accessed as a row of data to read, but you can use the column names to access a specific cell or column (by actions from the "Tables" group). If the option is off, the log will show "Columns: 3; rows: 3", the column names in the header will be ‘1’, ‘2’ and ‘3’.
For the "Remove duplicate header" option
- When true, the header of the tabular value that the actions return as a result will have indices added to the same column names. The numbering starts with 1.
Example No.1:
There is a table in a file with the extension xlsx:
With "Remove duplicate header" = true, and "With Header" = True, the "Take Table" action will return a table of 10 rows and 4 columns. The column names of this table will be "No.", "Robot Name", "Tests1", "Tests2".
Example No.2:
There is a table in a file with the extension xlsx:
When "Remove duplicate header" = true, and "With Header" = True, the "Take Table" action will return a table of 4 rows and 5 columns. The column names of this table will be:
"Test31", ‘Test21’, ‘Test22’, ‘Test32’, ‘Test1’.
- If false, the column names will remain the same. Actions on net that return/process such tables with duplicated column names will crash with an error, because net cannot have a header with the same column names.
- For example, the source table has columns "Test1", "Test" and "Test". If we add indexes only to the current doubles, the names will become "Test1", "Test1" and "Test2", i.e. new doubles with the name "Test1" will appear. Therefore, when renaming a particular column, the action should check if another column already has such a name and if there is such a match, the current column should have the next index. That is, in this case the action will rename the columns as "Test1", "Test2" and "Test3".
Example of use
Task
There is a file Book1.xlsx it is necessary to write values from row 1-4 of column A to the variable "Table", save and close the document.
Solution
Use the actions "Open", "Get table", "Save".
Implementation
- Assemble a robot scheme consisting of actions:
- Set the parameter for the "Open" action.
In the "File path" field specify the path to the file Book1.xlsx - Customize parameters for the "Retrieve table" action.
In the "Context" field specify the context created in step 1
In the "Start cell row" field specify the value = 1.
In the "End cell row" field specify the value = 4.
In the "Start cell column" field specify the value = A.
In the "End Cell Column" field, specify the value =A.
Specify in the "Result" field a variable of the "Table" type created in advance. - Set the parameter for the "Save" action.
Specify the context of the opened document in the Context field. - Launch the robot using the "Start" button in the top panel.
Result
The program robot completed successfully.
Cell values from the specified area are written to the variable "Table".