Dynamic Datatable

datatable

#1

Hi,

I’m new to UiPath and I was trying to do a prototype to scrap data into Excel table.

I formatted the data in txt file as following:

“ProductCategory,ProductCode,InitialExpense,RenewalExpense
A,0,162.11,0
B,1000,0,0
C,2020,0,13.11322602
D,2112,162.11,44.40943709”

How do I turn that into a dynamic datatable in UiPath?

I’ve tried using “Add Data Row”, but that only add all data into one column. How do I tell UiPath which column to add data in? Is there any easier way to convert the data into a excel table straight away?

Thank you very much for your help,

Cassie


#2

Since the file is comma separated, did you try changing the file extension to csv which can be opened in excel?

Path.ChangeExtension(file, “.csv”) ( Keeping txt file intact)

if you need to open in xlsx, then Read CSV >convert to datatable > write range to xlsx


#3

Hi @cassieyuan,

Actually, once you have added the columns to the datatable you can add the rows entirely with the ItemArray property, for example:

Also, be sure that your array of data contains the same amount of columns, otherwise it will throw an error.

Main.xaml (8.7 KB)


#4

Thank you, that solves my problem.


#5

Just as a sidenote:
There’s always the Add Data Row activity:

If there’s a premade (f.e. by MS or UiPath) activity to do the same, it’s 99% of the time more efficient to use those (in your example, at least 2 Assign’s and the InvokeMethod are superflous).

Especially if you fall back to using InvokeMethod, as it really does a lot under the hood to bind to the method to call, propagate arguments etc., while most activities use direct calls.
It’s still often a necessity (f.e. all void methods that don’t have an associated activity), but not in this case.


#6

Hello @vvaidya.
Can you please attach a sample workflow of the instructions listed in your post?
Thank you so much,
Camilla :slight_smile: