Assigning values to arrays

Hi. I am an absolute newbie.
I have n(unknown) number of .xlsx files in a folder. I am able to access the folder, and then serially read each file, and then close the file.

What I want to do is store each file in a data table (as is normal) and then store the data table in an array of data tables using Array of [T]-> System.DataTable. The variable is created. I would appreciate a link to all functions of the Array Variable, because in assignment, I am as of now unable to assign the data table to an element of the array.

Thanks

1 Like

Sorry i dont get the queries ?

You have multiple excel file in the folder ? Then you want to read the excel file one by one am i correct ? @Rpa_U9p1t8

cheers :smiley:

Happy learning :smiley:

1 Like

Hi @Rpa_U9p1t8

n(unknown) number of .xlsx files

First, since you have an unknown number of files, maybe List(Of DataTable) is better for the job.

Then, add each file’s datatable to the List using AddToCollection activity with TypeArgument as DataTable

I would appreciate a link to all functions of the Array Variable,

What do you mean by this though?

Thanks for the reply @marci080 .

Link…
I am not sure which all functions are available for the operations on an array. I thought I needed a list of functions for the array, but as you advised, a list of DataTable would be better, I am now trying to search a list of all the functions that can be used to manipulate or operate on such a list.
I did not get that in the documentations, so I wanted a reference to it if possible.

Thanks again

Thanks for the reply @pattyricarte

Yes. I have multiple excel files stored in a single folder, and I have to perform web-based operations on data within the excel sheet.
I can read the excel sheet one by one.
I can also read the data required.
The problem is that I want to put into a state machine structure, such that each of the excel files will be read in one go and stored in individual data tables. Since I don’t know the number of files in the folder, I have done the following:
image

Now I have a list of the names, but not the data in the files themselves.
So I want to store the data table generated from the read range into an array/list as advised by @marci080. I was trying this:


My error comes up in the last Assign activity.
My variables are as follows:

With the state machine situation, I have divided the input into states such that I first get a list of files. Then I want to read all the excel files into individual data tables and store all the data tables in an array/list. Then in the next, each data table is read and operation is performed.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Previously, using only sequences I was able to get the data onto the website from each file as follows:


image with the variables:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

With the state machine situation, I have divided the input into states such that I first get a list of files. Then I read and store all the data tables in an array/list. Then in the next, each data table is read and operation is performed.

1 Like

yes i think what @marci080 thougs is good also i noticed here.

cheers :smiley:

Happy learning :smiley:

2 Likes

That’s where I am stuck actually.
StoreExcel currently (before I posted here; haven’t made any changes yet), is of the type System.Data.DataTable. In each element of this, I want to save my data table generated by the Read Range operation on each excel file.

For a normal data table I can use .Rows(), or .Items(). But those functions don’t exist for System.Data.DataTable, or so it seems according to the error messages I was getting. So I wanted to know which functions could be used, and where I can get a list of these functions because I didn’t get them in the UiPath Docs.

On the RHS of the Assign Block, I have the output of the Read Range just before the For Each Block.
I don’t know what exactly to put in LHS. StoreExcel.SomeFunctionToAccessIndividualCellsOrElements().

Sorry to spam, and thanks for the replies @pattyricarte

1 Like

ah i think you need to use ForEacRow Activities to read the dattable .Dont use Foreach for the dattable type

image

cheers :smiley:

Happy learning :smiley:

2 Likes

Thanks I will try this!

1 Like

Hi @Rpa_U9p1t8, @pattyricarte

StoreExcel currently (before I posted here; haven’t made any changes yet), is of the type System.Data.DataTable. In each element of this, I want to save my data table generated by the Read Range operation on each excel file.

I think the For Each loop for StoreExcel is unnecessary.
As per my understanding, @Rpa_U9p1t8 just wants to save the datatables to the StoreExcel array.

If so,

  1. Change the StoreExcel type to List (Of Datatable)
  2. Initialize it to New List (Of Datatable)
  3. Then replace the said ForEach loop with AddToCollection
3 Likes

For Each Row won’t work for either a List or Data Table of a data table.

1 Like

Thanks. I will try this and update.

1 Like

I have performed the steps as you said. As of now there are no errors. Thanks.
I think this might be it, but once I am able to successfully iterate through each of the stored data tables in the next state, I will mark it as the solution, if that is alright.

Thanks again for your help @marci080, @pattyricarte

1 Like

No worries @Rpa_U9p1t8

Happy to help here :smiley:

cheers :smiley:

Happy learning :smiley:

1 Like

Hi @Rpa_U9p1t8

So I wanted to know which functions could be used, and where I can get a list of these functions because I didn’t get them in the UiPath Docs.

Just to answer this also. Since UiPath uses the .NET Framework,
you could actually refer to the microsoft docs for those methods,properties,etc.
https://docs.microsoft.com/en-us/dotnet/api/?view=netframework-4.8

Also in UiPath Studio, if you type the period (".") beside the variable name, the available properties and methods are also displayed.


Sample usage of the microsoft docs.

I noticed that you still have the Path.GetExtension(CustFile) = ".xlsx" checking.
You could define this as the searchPattern (ie. “*.xlsx”) when you performed the Directory.GetFiles() as indicated in the link above.

Glad to be of help. ^^

Happy learning :smiley: (as @pattyricarte always says) :slight_smile:

2 Likes

Thank you. Always eager to learn from people like you both :slight_smile:

1 Like

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