How to total rows present in a excel sheet?

Hi,

We get some daily excel reports on daily basis. In them we get a table in a sheet. What we have to do as a daily task to copy that table (no. of rows changes but overall structure of that table remain same) and send it via outlook.
For me the challenging part is to get the table range present in a excel sheet. So, as a solution what I am trying to count the total rows in a sheet.

What I trying to do I declare a variable and intialize it with 0 and then iterate for each row in the excel sheet and increment the variable . At last I print the value of the variable which contain the total number of rows in that table. But this is giving Error.

Hi @ujjwal.bansal
Welcome to Community!
Read the excel sheet then count the rows as dt_Input.Rows.Count.ToString
image

I hope it helps!!

Hi @ujjwal.bansal

  1. Use the “Read Range” activity to read the entire data range of the sheet into a DataTable variable.
  2. Use the DataTable.Rows.Count property to get the total number of rows in the DataTable.
  3. Store the row count in a variable for further use or processing.

Hope it helps!!

@ujjwal.bansal Your RowCount Variable type should be “Int”
and when you try to print it then use RowCount.Tostring
hopefully it will solve your problem instead of another logic.

@ujjwal.bansal As the variable type for count is Int, Try as DT.Rows.Count.ToString

Here DT is referrring to the name of the Datatable.

Thanks,
Mark it as Solution if it helps.

Thanks for your reply. But I couldn’t able to find “Read Range” activity in UiPath StudioX.

Thanks for your reply. I am new to UiPath. FYI I am using UiPath StudioX.

Hi,

Try this:

Excel Automation Tutorial with StudioX | UiPath

1 Like

Thanks for you reply. I have one question how to initialize a variable in UiPath studioX.

image

What I am thinking is “Save for Later” activity is to initialize a variable in my case that variable name is Val and I initialize it to 0.

There’s no point to putting it into a variable. Just put dt_Input.Rows.Count.ToString in the Message box.

There’s no reason to do any of this. You can just use yourDTName.Rows.Count.ToString to see how many rows are in it.

If possible can you post the image of complete workflow in UiPath studioX.

I’m not sure what you mean. I’m just explaining that you don’t need to do create a variable to store the count in. You can just directly use DTName.Rows.Count.ToString wherever you want to see the count. Put that directly into your message box (changing DTName to whatever the name of your datatable is)

I am trying to do something like this. But getting error. Please indicate my mistake.

You have to use Read Range to read the sheet into a datatable. Then your datatable has rows you can count.

Have you done the free training on the UiPath Academy web site? It covers how to do basic things like working with Excel, datatables, etc.

Hi @ujjwal.bansal

Try this to get the rowcount of the sheet.
Excel.Sheet(“Sheet1”).RowCount in the use excelfile.
Note:Variable should be of type int

Hope it helps!!