Copy and paste data from Excel

Hi everyone. I’m trying to grab data from a column in excel and paste it one by one on a website in chrome. For each cell, I have to grab a result, take a screenshot and paste it in word and restart the process with next cell within that column.

I’ve got the accessing of the browser part nailed down, I’m having trouble copying and pasting data from excel and repeating the process with each cell within a column. Any help is appreciated, thank you!

Use the UiPath.Excel.Activities.ExcelReadRange activity to get the data into a datatable. From the datatable, you can load each value into the website using a ForEachRow activity. This way, you won’t need to open Excel in your workflow.

So I’m using Excel application scope activity where I have Excel Read Range defined. I’m just confused on how to set up ForEachRow activity. Does that work for columns too? If so then how can I set it up to load data from data table and paste it by each cell, take screenshot of results and repeat for next cell in that data table?

For Each Row will iterate over the rows, but to iterate over the columns, you’ll need a For Each activity (not For Each Row this time) inside of your For Each Row activity. It’ll be For Each ColumnName in row.Table.Columns. Now each item can be fetched using row(ColumnName.ToString). This assumes that you’re using “row” as the variable name for your For Each Row activity.

You’ll need to add a Take Screenshot activity afterward when you put the data into the web application.

I see what you mean. I think I got it down. How would I paste the values into search box one at a time? Would the loop be able to go through each cell value in the data table automatically? I’m a bit confused on that and “fetched using row(ColumnName.ToString)”

Attaching my code. I took out the open browser activity that leads up to the search box where the values from excel will be pasted. But open browser activity was within for each activity. You are extremely helpful as I’m a beginner in Studio and I really appreciate your help :slight_smile:

Main.xaml (8.2 KB)

You will not need the Start Process activity in the Excel scope. Everything needed for reading the data will be done in the read range activity.

The best place I see to open the browser in this workflow is around the For Each Row activity. Then, after the browser is open, navigate to the page to input the data if it isn’t loaded immediately. In your For Each loop, use Set Text to set the data field to row(col.ToString). After the data is entered for that cell, you can take a screenshot, and do whatever is needed to prepare the next cell to be entered into the field.

However, it looks like you’re loading timecard data where each time card to submit is on a separate row with different fields (e.g. First Name, Last Name, etc.). If this is the case, it will be easier to do away with the For Each loop on the columns, and use Set Text for each field you’re updating (e.g., for a First Name field, you would set the text to row(“ColumnNameOfFirstName”), where "ColumnNameOf First Name is whatever the headers read from your file say for the First Name data.

*Removed Start Process (Didnt know i didnt need it, thank you!)

*Changed where open browser activity is around For Each Row activity (and yes the activity narrows it down all the way to the search field)

*Inside the For Each loop, you mention Set Text. Is that Set Text activity? When I use that, the only think I can do is add the text. Also is row(col.ToString) the exact expression or does col stand for the column name I’m using in my excel sheet? Still a bit confused around the whole pasting of values in search field in browser. But I’m closer to understanding it with your help!

*So yes I’m searching timecards but the column I’m using is all numbers. I’m using all numbers to look them up so no names or anything that I need to input. Just one field which will have numbers from the excel column thats needs to be searched one at a time.

Yes, the Set Text activity is what you’ll use to set the fields in the browser. Even if the field in excel is a number, it will still get posted to the browser field.

If you’re using only one of the columns in the data, you can reference the data in the cell with row(“ColumnName”), where “ColumnName” is the header of the column with the data you’re entering. You won’t need the For Each loop around the columns in this case; only the For Each Row activity.

*Ok, I understand Set Text and its purpose but how can I use that to post data from that column within excel, one cell at a time? I can indicate where it needs to be and the field for Set Text activity reads “Text must be quotted” Not sure what expression to use

*I only have one field that I’m using to search for results. I’m just not understanding how can I paste one cell at a time from that column and get results. I know I’m really close to the answer with your help but still not quite there.

*I’m attaching my sample code using google as a search field to substitute that with my actual browser activity. You have no idea how much you have helped me thus far, I seriously appreciate your time and dedication to help me understand the basics and concepts.

Main.xaml (10.0 KB)

“Some expression/Text?” should be row(“ColumnName”) where “ColumnName” is the name of the column from the Excel sheet. You’ll also need to indicate what box to put the text into in your Set Text activity. You will not need to click in the input box.

1 Like

Ok, I finally understand something so simple. I believe once I add the expression row(“ID”) into Set Text, it throws out an error. “Option strict on disallows implicit conversions from ‘object’ to ‘string’” and I believe I might have mismatch in data types?

Main.xaml (8.5 KB)

Change it to row(“ID”).ToString, and the code should work.

2 Likes

Genius! That solves the Search problem, thank you! So obviously as this is a loop, it will keep going, but where do I add the screenshot activity so that it can take a screenshot before moving on to search the next ID?

Would it be possible to simultaneously paste those screenshots from local save (as I believe they might be saved there?) into a word doc after each search? Or am I better off creating a second automation for copy and paste data into word doc?

The topic of saving the screenshots is more complex and would require another thread, but you can put the screenshot activity wherever in the process flow you want to capture the image of the screen (e.g. after you’ve set the text in the field).

1 Like

Really appreciate your help with this, thank you and have a great rest of your day!

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