Hi all,
I would like to rename a column which matches particular string in column.
Check out the Video link
Can you share the sample input and expected output?
Assign activity: yourDT.Columns(0).ColumnName = âNew Column Nameâ
The 0 is the column index, which you have to set for whichever column you want to rename. 0-based index, so if you want to rename the third column youâd use Columns(2)
Or you can reference by column nameâŚ
yourDT.Columns(âOld Column Nameâ).ColumnName = âNew Column Nameâ
The problem here is the index might change and column name partially contains text
So use the column name.
Every column name is entirely text (string).
For example column name has value âPhoneâ some other time it contains âPhone#â, so i need to change the whole column name as âPhonenumberâ
Why is the column name different like this? That shouldnât happen, and is the issue you need to resolve. What is creating the datatable? Read Range? Something else?
Are you sure youâre talking about the NAME of the column, not the data (the rows) in the column?
i am not using excel, I am using cv extract table. Thats the reason I am getting the column name differently each time
Set âAddHeadersâ to false in the CV Extract Table activityâs properties. Then the columns will always be the same ie Column1 Column2 etc
the table is spanning to multiple pages, then multiple headers will be added
You canât have multiple headers in a datatable. Each column has a name. There is only one name for a column.
Are you sure youâre talking about the column names and not the data itself, the values for the rows?
Again, turning off AddHeaders in the activity will make it so the datatable is created with generic column names.
Hereâs how I have done
-
Used For each Activity to Loop Through Columns in Datatable
-
Assign Column name as you want to The Current Column Name
In my case, I wanted to Assign the value below the current column i.e. cell value of current Index of Column from 1st row.
Used index generated from the output of For Each Activity
Hereâs the Assign expression
ExtractRecoveriesDT.Columns(columnIndex).ColumnName =>
If(ExtractRecoveriesDT.Rows(0).Item(columnIndex).ToString <> ââ, ExtractRecoveriesDT.Rows(0).Item(columnIndex).ToString,currentItem.ToString)
Used Conditioned-If Statement to Neglect the below error:
Assign: ColumnName is required when it is part of a DataTable.
Note: This Error Comes when Thereâs a null or ââ value while assigning a column name
Iâm using studio x and assign not available. what can I use instead?