I am currently trying to make a very simple automation , one that would duplicate the selected column(s) from an excel file and add them to the right of the existing ones. However , as I am trying to do the basic part of it (aka adding the column) , I get an error stating that “column 1 already belongs to this datatable” , which makes sense. However , when I try to give it a name ((DTTable.ColumnCount +1).ToString) , I get the ensuing error that the overloading groups Column and Column name should not both be configured at the same time.
How could I work around that issue ?
Thank you in advance ,
Hello @B_Bastien ,
You can use Insert Columns Activity to insert the New columns. You can provide new Name for the columns and the position. Then You can use Read Range on the required column and use Write Range to write it to the column which you newly created.
Hi @B_Bastien ,
Could you provide Sample Inputs and Expected Outputs for it ?
We could simply understand the Logic faster this way and provide/suggest you a better solution.
We do understand you would want to Duplicate Column Values, but is it only a Specific Column and are we duplicating it only once or as many times as Required ?
Hello @Rahul_Unnikrishnan ,
The issue is that I am working outside of an excel app integration , as I don’t necessarily want it to be outputted in an excel file , or even as the original input , if I want it to be easily integrated into other , wider workflows later…
Thank you for the hint however !
Hi @supermanPunch ,
The input is a single column excel file (for now) , and the expected output would be a two-columns one , however for a wider table , it’s placed within a for each activity , and should add a duplicate of each column at the end (which I assume is on the right) of the last existing one , effectively making a duplicate of the table on it’s right after the loop is completed , so once. As I’ve built it yet it probably will loop until I force it to stop , but that much shouldn’t be too hard to solve.
Do you want me to provide with the workflow I’ve made so far and the input excel ?
Thanks in advance ,
Check the Workflow Below :
DT_DuplicateColumnValues.xaml (15.7 KB)
Initially, we have the Datatable as below :
After the Operation/Execution , we end up with the below Datatable :
We make use of a Dictionary to Point out the Columns to be Duplicated and How many times :
We Add a Column at the Beginning to the Input Datatable, A
Key Column which can be used to uniquely Identify the rows of the Datatable, We populate the column value in each row Incrementally, this is used to Later Combine the Input Datatable with the Temporary Datatable with the Modified Column Names :
We Create a Datatable Temporary to hold the Column to Duplicate along with the Key Column, Then we change the Name of the Column to Duplicate :
You could delete the Key Column at the End, as it is used just to Combine two Datatables.
Let us know if you are still facing difficulties.
Wowh , okay , I hadn’t thought of using a dictionary that way .
This is awesome , many thanks for that , I’ll try experimenting with your solution!
You can also use this approach
Copying the schema of the original table
dt_Out = dt.Clone
Adding the Columns to the dt_Out using the invoke method activity
Adding the values to the dt_Out
From row In dt
the parameters of invoke method activity
The xaml is attached
DuplicateTheColumns.xaml (9.7 KB)
This is a very cool way of approaching it , thank you a lot for that, I would honestly not have thought of it in the slightest!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.