Read Excel sheet and do calculus operations based on condtions update it

Hi Uipath,

I’m new to uipath and trying to solve one task.

  1. Read the file Calculus.xlsx[Calculus.xlsx. Add a new column Result. If number 1 > number 2, subtract, else multiply them.

  2. Expect a tax rate of 15%. Add another column that adds the tax rate to the result. This calculation should be done in the Windows calculator.

  3. Save a new Excel-File with the results – the naming of the file follows this naming format: YYYY-MM-DD_Results.xlsx.

I had been done the process getting the error.
error: datatable collection is modified.

kindly let me know the solution for this.

Attaching my code and excel.
Main.xaml (16.9 KB)
Calculus.xlsx (9.0 KB)


Let’s go one by one

  1. Use excel application scope and pass the file Path of calculus file as input and inside the scope use the read activity and get the output as dt
  1. Now use a add data column activity to add a new column to the above datatable dt
  1. Then use a FOR EACH ROW activity and pass dt as input
    Inside the loop use a IF activity with a condition like this


If it’s greater it goes to THEN block where use a assign activity to subtract the value using assign activity like this

CurrentRow(“Result”) = (Convert.ToInt32(CurrentRow(“yourcolumnname”).ToString) - Convert.ToInt32(CurrentRow(“yourcolumnname”).ToString)).ToString

If not it goes to ELSE block where multiple the value using Assign activity like this

CurrentRow(“Result”) = (Convert.ToInt32(CurrentRow(“yourcolumnname”).ToString) * Convert.ToInt32(CurrentRow(“yourcolumnname”).ToString)).ToString

  1. Again same with add datacolumn to add new column for that tax rate and use some set of click activities to perform the calculation in windows calculator

  2. Finally to save the file with the filepath we need, use a MOVE FILE activity and mention like this in the property panel

From or Source - mention the current FilePath

To or Destination - mention like this

Path.GetDirectory(“your current folder path to the file”)+”\”+Datetime.Now.ToString(“yyyy_MM_dd”)+”_Results”+”.xlsx”

Cheers @personal_mail

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.