I’m trying to delete some columns inside a data table - which is the output variable from read range activity - before writing the data table into CSV File. I only need some specific columns in the CSV file.
What would be best way to do that? Please suggest.
Download and install below package and then use Select certain Columns activity to read certain Columns. You need to pass DataTable and required Column names in Array of a string format.
@ppratz
Nope, you have to click on plus (+) to add more column names… as shown in below image.
Instead of adding more no of columns, if you want to remove 1 or 2 columns you can simply select remove radio button and mention columns which you want to remove from datatable.
Hello @lakshman , some time ago I saw that you could do something like this using assing and with the following sentence dtName.select (“[Column1] = ‘value’ AND [Column2] = ‘value’”). CopyToDataTable, could you explain to me what value go in [Column *] and in “Value”
I needed something similar but my case was simpler, I only needed to keep only the 1st column so I made this little loop to remove the other columns… (see picture)
It removes the 2nd column every time (index =1) and the loop keeps running till we have more than 1 column
But if you wanted to keep specific columns, for example 3 firstname,lastname,salary
you could modify it, do something like this:
First create string array of the columns you need
mycolumns = {“firstname”,“lastname”,“salary”}
Also make an int32 counter like (to remember how many columns you already have):
keep=0
then change condition so you run it until you have more columns than you wanted
InputDT.Columns.Count > mycolumns.count
and inside you could check if column name is in your list, if yes keep it and increment the index otherwise delete it and keep running the loop
if( mycolumns.Contains( InputDT.Columns(keep).ColumNname )
then assign keep = keep+1
else remove data column with index keep
[EDIT} In case my explanation is hard to understand, I’ve done it for ya:)
Advantage of my solution is you can change the NeededColumns dinamcally (especially if you change it to list instead of string array), that you cannot do in Filter DataTable activity