Hello guys, I am trying to create a table to write it to an excel file, i have two files: one txt and another csv and i am iterating through all the rows of these files.
1st question: how do i initialize a table? using assign table?
2nd question; how do i add an element to this table? i would need to insert the value of a list (each row of these files) to the table or is there another approach?
any help would be great!!
Page 1 / 1
You can read the entire contents of CSV and TXT files using the aptly named CSV/TXT package.
Most of the time, you don’t need to initialize a data table variable, the actions in which their output is a data table change the schema of the table: i.e.: the headers, number of columns, number of rows, etc.
Here’s an example:
If your TXT file looks like this:
Department Finance IT Human Resources Sales
You could create a task bot like this one:
And the contents of the output data table variable would look like this:
However, if your table variable does not follow the same schema as the source TXT/CSV, you can set up a different schema for that variable in the Variables panel by clicking the “Edit table (1x1)” button.
When you click that button, a dialog will come up where you can specify the name and data type of the columns as well as the number of rows and columns.
You can also do an in-line initialization with the Data Table: Assign action. That action also contains the “Edit table (1x1)” button, and it works just like the one in the Variables panel.
As for your second question, there are a couple different ways to add an element to a table variable, each with its own pros and cons, so it really depends on your use case.
These are some of the simplest ways to set the values of a table: