Copy dataTable row to another dataTable

datatable
excel
activities

#1

Hi!
I have tried to figure this out for a week now. So my problem is i have one big excel file with 12 columns in one row and it has lot of rows. Now i want to divide it to different excel files depending on one column. I have figured out how to get the specific row but now i need to add the rows to the new datatable that i can create the file. How to do that?
Now i have done it so that
i go through for each row in the datatable
and inside the loop i use get row item
then i use add data row with these array of values what i get from get row item

But this cannot be the way… i have now 12 variables just used with that get row item and i have done that get row item for each column.
I have tried also to get for each row and then add that row to this new datatable but it say’s that _ This row already belongs to another table_ is there any way to do that more efficiently?


How to calculate data of different columns and keep the unqualified ones in another excel sheet
Copy/Paste selected value only into new excel
#2

Hi,

Steps for the solution which you can follow:-

  1. Read the excel sheet range into a datatable (dt) using read range activity.
  2. Create a new datatable variable in the variable section say newDt
  3. Using an assign activity, you can directly copy the data to the newDt using the below expression
    newDt = dt.Select(“Your Filter Expression”).CopyToDataTable() (Your filter expression has to be like ColumnName=Value)
  4. Write the newDt to the new excel

Refer to the link below (It’s in C# but works in VB.Net as well)
http://stackoverflow.com/questions/2122511/simple-way-to-convert-datarow-array-to-datatable


Copying Excel data from one workbook to another
Delete Row in excel
#3

Oh that would be really great. But my “filter” contains a string. And it doesn’t seem to understand when there is spaces and comma in the string.
Or could i do something like DT.Select("CollumName=’ " + StringValue + " ’ ").CopyToDataTable.
Have you tried this method? Does it work, it would be super handy way to do that.


#4

It works fine for me with spaces and comma within a string inside a filter expression as well. And the it should also works with a variable as you have mentioned above.

Regards,
Sachin


#5

Woo! It works, Thanks a million! Super, you made my day, thank you so much :slight_smile:


#6

Hello Jmati,

Would you care to share you UiPath xmal file? I am looking for a similar solution to yours.

Thank You


#7

Hello,

I have the same issue, did you still have the xaml file?

Regards.


#8

Hello Sachin,

I am new in uipath and i have exact job like that. I couldn’t make the steps you said. Do you have xaml file?

Thanks.