hey cameron mckenzie here at cameron mcnz on twitter if you want to do a follow and right
now i want to talk to you about data tables and specifically how to take a data table and
save that data table to excel using uipath now i'm not going to grab a data table by pulling
it from some csv file or something like that i'm going to actually create a data table from scratch
i'm going to manually append rows to that data table show you how those operations work in uipath
and then when i've got three or four different rows entered into the data
table i'm going to save it all to excel and then you can take
these features and then plug them into any other complicated routine that you may have
but this will show you exactly how to do that that's save a data table to excel as always
i'll kick this off by creating a new project and i'll call it the add a pen data table
create excel because these are all the things that i'm going to do in this particular project
and as soon as project window starts up i'll open the main workflow and the first thing that
i'm going to add on here is a build data table activity so you can find available programming
data table build data table drop that on here and you're on your way to building crazy data tables
now when you do this you need a variable to hold all the data in your data table so i'm going to
create a variable called my data table and it's going to be of type data table system dot data
table that doesn't come up right away you can always browse for types and look for data table
there's a million of them make sure you pick the right one it's system.data.datatable
and now you can associate this build data table with that variable you just created my
data table so now you're going to be able to use that on multiple operations as you
add data to the data table now this actually creates a really lame data table because it's
only got two columns in it and if you create a data table you want to create
three columns because three columns are cool so i'll call that the third column
it'll be of type string and the default value
i'll just make it third and you can see here and that was just by clicking this button
here to add the column so you see i've got one column here and i'll call that the first column
the second one is of type in i'll call that the second column it's a type int of allows nulls and
then i got the third column i created so there you go that's how you create a basic data table
with three columns in it now what do you want to do this is going to be blank actually it's not
going to be blank it actually is going to put text one and third in the table automatically
so if you don't want default values in there for the first record you can delete those but we're
going to do it the more the merrier but i want to have more than one row in that data table so what
i'm going to do is i'm going to look for that add data row activity and it's right there data table
add data row i'm going to drag this below here now what data table do i want to work with well
it's called my data table so i'll click on add data row put my data table in there and then
you've got this option for array row to add an array of values in here and it's just the basic
array syntax i want to say well the first variable is a string the second one is an int third one is
a string as well and now that adds one more row to the data table i'm going to oh what's the
warning that i've got there one or more children have validation errors in it and it would appear
that i didn't close my i didn't put a column in after the one yeah well that would be worthwhile
doing yeah just make sure that make sure you get the right syntax because if it doesn't compile
it's not going to work i forgot the comma after the one right there's three different columns
that we need to work with okay with that done i'm going to copy that and then paste it twice
and then in the second column i'm going to change it to goodbye world and put the number 2 in there
and then for the third column goodbye world kind of sounds a little suicidal so i'm going to say
i'm back and i'm happy and put the number three in there for world and there we go we should have
four call four rows in our data table the default values text one and third and then the three
different rows that i've added now again make sure that each of these rows has my data table
as the data table type there if you don't you'll end up with null runtime exceptions we do not want
those okay so essentially for as far as creating a data table goes and adding rows to a data table
i'm done but it's always nice to get some visual feedback to make sure that you've actually done
all of this properly so why not write all of this to an excel file so this project called add append
data table create excel i'm going to find that in my uipath folder there it is and inside the
project root i'm going to create a brand new excel worksheet and i'm going to call this append add
dot xlsx didn't mean to open it well when you open it you can see that it is indeed blank there's
nothing in it right now but i'm going to copy that name i'm going to copy that name go back into
uipath and then look for the excel active activity that allows you to introduce an excel application
scope i'm going to drag that right down here and in quotes i'm going to provide the name of that
excel file append add excel it's just the file that i just created in the root of that project
and now i can manipulate that and what do i want to do i want to add all the data in
this data table to that excel file and so to do that the operation is known as the append range
and so there's the append range activity i'm just going to drag it right in there
sheet1 is the default that's okay and what data table do we want to put in well it's this data
table here my data table that we created and have been manipulating and adding rows to and
so this should open up that append add excel file append my data table to the first sheet
and then close the excel file and that's about it i'm just going to take a quick look make sure
there's no exclamation points also i like to make sure that yeah that data table is there
the data table is there the data if you forget it anywhere the program's not going to run so
just make sure that you've got that correct and i think this all looks good i'm going to click save
and then run this file hopefully no errors happen nope it comes back and it says that it executed
quickly and i'm going to open up this file and notice inside this file i have those four rows
hello goodbye i'm back one one two three robo world third and that one was the default that
happens when you create your data table just in case you're wondering where that one came from
when you create the data table notice it has text one and i put third in there but that's
the columns that are automatically added to the data table initially
and there you go that's how you create append and save data tables into an excel file and there
you go those are the ins and outs of saving data tables to excel now if you enjoyed this tutorial
why don't you head over to theserverside.com i'm the editor-in-chief over there we've got lots of
great articles on enterprise software development and tutorials on uipath if you're interested
in my personal antics follow me on twitter at cameronmcnz and as always subscribe on youtube