Search code examples
uipath

UIPath - Get a single row of a datatable and write it in Excel


What's the best way on UIPATH to get a multi column row of a Datatable and to write it on Excel.

I'm in this situation :

  • I converted an Excel table into a Datatable with ExcelReadRange
  • I'm using a ForEachRow loop to get every row of my datatable
  • inside this loop I'm using an ExcelWriteRange activity to write each row on the same range of my Excel File. (so yes I replace the row at each turn of my ForEachRow loop)

But I get the next error :

Impossible to convert a System.Data.DataRow to a System.Data.DataTable

So I made a new Datatable with BuildDataTable and used Add Data Row and provided the target row. Thanks to that I can provid the new Datatable to my ExcelWriteRange. But it's still not working and I get this new error :

This row already belongs to another table

What's the solution to write row by row my datatable in Excel ?


Solution

  • The solution is to provide the row as an ArrayRow and not as a DataRow to the Add Data Row activity

    DT_row.ItemArray