vaishali
(vaishali)
August 11, 2023, 6:46am
1
Hi Team,
I need to change the row as bottom to top without giving any condition in csv file…
Example
Col1 col2 col3
1 aaa ww
2 bbb yy
3 ccc mm
Output:
Col1 col2 col3
3 ccc mm
2 bbb yy
1 aaa ww
Kindly provide any solution for this…
Thanks
1 Like
Hi @vaishali ,
You can try this Step
Get the Row having Total in it’s First Column
Convert the Row to Object Array and Store it.
Delete the Total Row from the Datatable.
Use Add Data Row Activity with Object Array as the input value which in turn contains the total row value.
regards,
LNV
1 Like
mkankatala
(Mahesh Kankatala)
August 11, 2023, 6:55am
3
Hi @vaishali
=> Use read csv activity to read the csv file and store it in a datatable. Output - dt_csv
=> After this take an assign activity and create another datatable variable, let’s call it as dt_Reversed.
- Assign -> dt_Reversed = dt_csv.AsEnumerable().Reverse().CopyToDataTable()
=> At last, use write csv activity to write the dt_Reversed datatable to csv file.
Hope it helps!!
lrtetala
(Lakshman Reddy)
August 11, 2023, 6:56am
4
Hi @vaishali
You can simply try this
ReversedDataTable=(From row In DataTable.AsEnumerable() Select row).Reverse().CopyToDataTable()
1 Like
vaishali
(vaishali)
August 11, 2023, 7:20am
5
Thanks for the input… Its working as expected. But once we write the output its creates the empty three rows. May I know why we are getting that again .do we need to delte the empty row… Please suggest.
1 Like
vaishali
(vaishali)
August 11, 2023, 7:21am
6
Thanks for the reply. As i said we are getting some empty row… Do we need to write the code to remove the empty row.
lrtetala
(Lakshman Reddy)
August 11, 2023, 7:28am
7
@vaishali
Is the empty row adding first or in between can you show some screenshot how it looks
ppr
(Peter Preuss)
August 11, 2023, 7:55am
8
Assign Activity
dr1 | DataType: DataRow = YourDataTable.Rows(0)
Assign Activity
dr2 | DataType: DataRow = YourDataTable.AsEnumerable().Last().ItemArray
Assign Activity
raTMP | Object() - Object Array | dr1.ItemArray
Assign Activity:
dr1.ItemArray = dr2.ItemArray
Assign Activity:
dr2.IttemArray = raTMP
EDITED - Shortened
Assign Activity
raTMP | Object() - Object Array | YourDataTable.Rows(0).ItemArray
Assign Activity
YourDataTable.Rows(0).ItemArray = YourDataTable.AsEnumerable().Last().ItemArray
Assign Activity:
YourDataTable.AsEnumerable().Last().ItemArray = raTMP
1 Like
vaishali
(vaishali)
August 11, 2023, 8:01am
9
Yes its working as excepted thanks
1 Like
ppr
(Peter Preuss)
August 11, 2023, 8:20am
10
Perfect, so it is ensured that your data table row count will always be 3
system
(system)
Closed
August 14, 2023, 8:20am
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.