Extensive utilization of Excel


#1

Hello There,

I am unable to read the excel in the requirement format for example attached the sheet.

In the sheet there are two table’s i was able to read the first once as its “static” shown below how ever recognising Column as a header is also been worked upon.
image

However i am unable to read a dynamic table highlighted below in the same sheet as there is possibility of having more row which cant be predicted.

Can you please assit me on how to read both the table from single sheet only.

Best Regards,
Syed.Testcase.xlsx (11.6 KB)


#2

Hi Syed,

There is an Extended Excel Activities package that you can download that will allow you to work with tables of varying size. Try following these steps:

  1. Go to https://gallery.uipath.com/packages/UiPathTeam.Excel.Extensions.Activities
  2. Click the download link under ‘Package History’ for version 1.0.3
  3. Locate the downloaded .nupkg file and move it to C:\Program Files (x86)\UiPath\Studio\Packages
  4. Within UiPath Studio, go to the Package Explorer (see screenshot below)
    package
  5. Install the Excel.Extended.Activities package
  6. Restart Studio
  7. At this point, the package should be included in your Activities library. Try using the Get Last Row activity and store the result in a variable. Then you can use this variable to select your range.

Hope this helps!

Best,
Nick


#3

I had a similar process that used a single excel sheet and needed to create 2 tables of varying length. I posted a question about it here: Extract beginning portion of data table only

I went about it by doing the following:

  1. Read range on excel file and get the entire sheet into a single datatable variable.
  2. Find the first blank row after the 1st excel table & store as an integer variable “N” - this helped me know where to separate the tables.
  3. Clone the original table from step 1 into table1 and table2 datatable variables using an assign activity
  4. Use the datatable method .take and .skip to separate into 2 tables. To do this, assign RowsToAdd = datatable.AsEnumerable().take(N-1) or .skip(N+1). This should be of variable type IEnumerable Then use a for each to iterate over RowsToAdd and use the invoke method activity on the table1 and table2 variables using the ImportRow method

However, your case might be a bit easier. It looks like the first table you’d like is always going to be in cells A3:B8, correct? If so, then you should do the following.

  1. Read range on excel specifying range A3:B8 and that the data does not have headers
  2. Read range on excel specifying range A10:F10000 (or however many will definitely be more than the most rows you’ll ever have). Make sure to check the box that data contains headers
  3. Use a .Select statement on table from step 2 to get Blank rows
  4. Use a for each datarow on the datarow collection from step 3 and delete them

#4

Hi Dave,

Thanks for the reply however can you please assist me with the sample i was unable to find a solution on your point3.

I am saving my sample xml for the sameproject2.zip (11.7 KB)


#5

Dave excelextend.xaml (12.0 KB)

See the attached sequence describing my 4 steps. I left it within your overall “for each file in directory” structure, but I would recommend separating that out. You should use directory.getfiles and save as a list of string, then make each file it’s own transaction either through orchestrator or through other means. This will make it much easier to follow your workflow as it gets larger instead of containing everything within a single for each loop.

A couple changes I’d point out that I made as well:

  1. You don’t need to use a Word Application Scope when changing objects to string.
  2. You don’t need to use an assign activity to change the directory.getfiles items to strings. I just changed the For Each TypeArgument to string, as that is what is natively returned from directory.getfiles anyways.
  3. I used a Read Range activity instead of containing it within the Excel application scope. This way the computer that runs the robot doesn’t need to have Excel installed. Go ahead and keep it within the application scope if you want to export the Excel variable, or need to use activities that require it to be in the Excel application scope such as execute macro.
  4. No need to use the “output data table” activity. That is already done as part of the Read range activity

#6

Thanks Dave my issue solved it was great help