Get table Version 2 (Python)

Action group: Office


Description

The action saves the table from the document to a variable of type Table

Action icon

Settings of parameters

PropertyDescriptionTypeFilling exampleMandatory field
Parameters
ContextContext for working with a documentRobin.OpenTextDo c
Yes
Table numberThe number of the table in the document. The order starts from 1. The default value is 1Robin.Numeric
No
HeadingIf the value is «true», the table header will be inserted into the document along with its rows.Robin.BooleantrueNo
Remove duplicate headerIf 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.BooleantrueNo
Results
ResultResult tableRobin.DataTable

Special conditions of use

For the "Heading" parameter: 

Take table:

If the "Heading" parameter is turned off, the "Insert data table" action will have the following message in the log

If the "Heading" parameter is turned on, the "Insert data table" action will have the following message in the log

 


Let's consider an example on getting a table and inserting it into a document depending on the configured parameter "Heading". 

The robot scheme consists of actions: "Open", '"Get table", "Save", "Insert data table", "Save". 

 

The table shows an example of the result depending on the filling of the "Heading" parameter.

No.Filling the "Heading" checkbox for the "Get table" actionFilling the "Heading" checkbox in the "Insert data table" actionResult
1

true

true

2falsefalse

3truefalse

4falsetrue

Thus, if "true", the action will keep the first row of the source table in the header of the returned tabular value, i.e. it will not be the row with the table contents.
 When "false", the first row will remain in the table content part, and the default names will be used in the header - 1, 2, 3, etc.

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:

With "Remove duplicate header" = true, and "Heading" = 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:

When "Remove duplicate header" = true, and "Heading" = 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 test.docx. You need to open the document and get the table with data from there (there is only one table in the document). Then, save the document and close it. 

Solution

Use the "Open", "Get table", "Save", "Close" actions.

Implementation

  1. Assemble a robot scheme consisting of actions:
  2. Fill in the "Open" action parameter. 
    In the "Path to file" field specify the path to the file test.docx



  3. Set the parameters for the "Get table" action: 
    In the "Context" field, specify the context created in step 1
    In the "Table number" field specify -1. 
    In the "Result" field specify a variable of the "table" type, where the obtained table with data will be written.

  4. Set the parameter for the "Save" action. 
    In the "Context" field specify the context of the opened document.

  5. Move the "Close" action to the workspace and set its parameter.


  6. Click "Start" in the top panel.

Result

The program robot completed successfully.

The table from the document has been successfully saved to a variable.  The file is saved and closed.

  • Нет меток