How Can I sort 3 columns without opening csv and save to the csv?

I have to sort 3 different columns on Csv file and save to it. Can someone help me here ? I don’t want to open and close csv file each of the time.


  1. Use read csv…
  2. Then use sort datatable activity
  3. Write csv



First read the csv file and store the data to datatable by using Read CSV activity.
Then sort the datatable by using sort datatable activity you can sort the table ascending or descending by changing the Order property in sort datatable activity
Then write the sorted datatable to csv by using write csv activity.
The write csv activity will create a csv file if file is not exist, it override the data the file if file has already data in it.

Check the below workflow.

Hope it helps!!

It will help but every time I have to read and write csv for all 3 columns. and this is taking so much time. Is there any other way that I can do it all in one?

No. CSVs are just text files. They don’t have sorting features. I don’t know if it would be any faster, but you could try opening it in Excel, sorting, then re-saving as CSV.

Ok, Thanks for suggestion. I will try to copy the data in Excel and then after sorting will convert in .csv

Don’t copy the data into Excel. Open the CSV file with Excel. Excel can natively open CSV files.

I am opening .csv in excel and then creating table for that column data. now sorting that table using sort table activity but somehow it says invalid table name in create table activity. Table name I try with different names.

Open the CSV in Excel. Save as .xlsx with a different name. Those two steps are done with UI automation (ie clicking around in Excel). Use Excel activity, inside it use the Sort Range activity. Once it’s sorted, save it back to CSV (again with UI automation).


We can do this by using excel activities but we have to use much activities to do this automation.
→ Use the read csv activity to read the csv and store it in a datatable.
→ Use write range workbook activity to write the datatable to excel (.xlsx) file.
→ Use excel process scope and use excel file inside that use sort range activity in excel activities to sort the three columns one time.
→ Use Read range activity to read the excel to datatable.
→ Use write csv activity to write the datatable to same csv file.

For your reference follow the below workflow.
Main.xaml (13.9 KB)

Note : Change the Excel and csv file paths in the workflow.

Hope it helps!!

Hi @mkankatala Thanks for the explanation with flow. Somehow the activities you used in excel , I am not getting it. I am using Excel version 2.16.2. Please advice.

Certainly! I can help you with sorting the columns in a CSV file without opening and closing the file each time using UiPath.

Here’s an example workflow using UiPath Studio:

  1. Read the CSV file: Use the “Read CSV” activity to read the CSV file and store the output in a DataTable variable, let’s say “inputData”.

  2. Sort the columns: To sort the columns, you can use the “Sort DataTable” activity. Configure the activity with the following properties:

    • Input: inputData (the DataTable variable)
    • SortColumns: Specify the columns you want to sort and their sort order. For example, if you want to sort Column1 in ascending order, Column2 in descending order, and Column3 in ascending order, you can provide the following expression: “Column1 ASC, Column2 DESC, Column3 ASC”.
    • Output: Create a new DataTable variable, let’s say “sortedData”, to store the sorted result.
  3. Write the sorted data to a new CSV file: Use the “Write CSV” activity to write the sorted data to a new CSV file. Configure the activity with the following properties:

    • Input: sortedData (the DataTable variable)
    • FileName: Specify the path and name of the new CSV file where you want to save the sorted data.
  4. Repeat the above steps for each set of columns you want to sort.

By following these steps, you can sort the columns in a CSV file without having to open and close the file multiple times.

Please note that this example assumes you have UiPath Studio installed and have basic familiarity with using it. Let me know if you have any further questions or need additional assistance!

You have to install the UiPath.Excel.Activies package in the manage packages to use the Excel activities.

You can go through the workflow I created I have attached in the above replies. Download that xaml file and see the activities what I used and workflow.
The attachment is in the name of Main.xaml

Hope you understand!!

I have already installed it. But not getting any option of the activities which you using in your workflow.

Are you using the UiPath studio or studio x.

If you downloaded the file open the file with UiPath studio.

If you are unable to see the Excel activities open the activities panel and search for the Excel.

If you are getting any error send the screenshot.

I am only getting Sort table and sort data table activity. I am not getting the sort column activity inside excel as in your workflow.

Can you provide me an sample of step 2 ?

Thanks in Advanced.

Hi @Anil_G I am using the same. But I am getting error on Sort table activity. It says Column name not valid. EX: I have column “pqr” I copied same and pasting into that sort column properties.

Then, writing the same data into that file using write csv file. (Is it the issue of writing data into same sheet ? I mean overwritten ?)

Install the UiPath.Excel.Activities then you can see the excel activities in the activities panel.
Search for Sort Range in the activities panel. Then drag and drop the activity.


Click on the Add Sort Column then we will get the Sort by column in it.

Hope it helps!!

I am only getting this.