Read data from Excel spreadsheet and write text files for each row entry


I am new to UIPath and am looking for the best approach to automate the reading of row items in my excel spreadsheet (each row is a unique entry - for example a patient) and then to create individual text files for each row. The text files will then be read by my application.

I assume the best approach is to create a data table from the excel spreadsheet in UIPath? Once I have the data table created how do I transform the rows into files?

My table has four columns, surname, forename, birthdate & patient number. I wish to create a text file for each row in my excel spreadsheet. There are 25 rows in my spreadsheet for testing.

Any help would be gladly appreciated!


1 Like

You can just use foreach row activity to iterate the number of rows in UiPath.

Then in the do block of for each please add write text file activity and write back the formatted string containing your row data to save it.

Hope this helps



Hello @andrew.haworth

Welcome to Uipath Forum.

Please use the below,

For each row in DataTable

Assign surname = CurrentRow.item(“surname”).ToString

Assign forename = CurrentRow.item(“forename”).ToString

Assign birthdate = CurrentRow.item(“birthdate”).ToString

Assign patientnumber = CurrentRow.item(“patientnumber”).ToString

Use Write Text File Activity to write the required Text

Please try and let us know if you are able to achieve what you are trying to do.
Happy automation.


1 Like

Hi Jesh,

Many thanks for your quick reply. I include a screenshot from my studio session:

Where do I enter the “Assign” commands?



1 Like


Write the variable names (say surname) to the left (you shall press ctrl+k to create new variable before assigning) and the CurrentRow.item(“surname”).ToString to the right.


I have now added the variable names as described.

When I run my automation I obtain the following error:


Am I missing some additional configuration?


This error is occurring as the Datatable NEW_PATIENTS is empty.

Can you check and confirm if the datatable contains any rows in it ?

To confirm this please check the output of the Data Scraping you used above the For Each Row.


Use the for each row activity combined with write text file activity, making sure that the file names are unique. For example, you can use the index property of the For Each Row to append at the end of the file name. Also, set the TypeArgument property to String. Do these from the properties panel.