cancel
Showing results for 
Search instead for 
Did you mean: 

Get number of cells in an excel

UditKhanna
Level 3
Hi Community, does anyone know a way to count number of cells present inside a particular column of a sheet.

The requirement is to get the random value from any column, as of now i am following the below steps:

  • Counting total number of rows, let's say it's 10.
  • Generating a random number between 1 and 10.
  • Returning the collection value of that particular random number i.e. it acts as an index.
The problem with this approach is that we are having dependency in the first step, to count number of rows we must have equal number of cells in every column, else it may return the blank value. Just want to remove that dependency. 
If someone has a better approach then i am open to that as well.
Thanks

------------------------------
Udit Khanna
------------------------------
1 REPLY 1

Hi Udit,

For this use case you can use the "Data - OLEDB" VBO which will read your excel file as a database using the ODBC drivers. In order to properly work with this VBO, you can refer to the following training LMS as well: Blue Prism Guide To OLEDB

- For this VBO to work, you need to install the Microsoft Access Database Engine which you can get from Microsoft's website as well which is given under the training resources. Once you get the DLL installed. You can use the action "Set Connection" of the "Data - OLEDB" VBO to first establish a successful connection with your excel file by providing a valid connection string, for example, Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<FILE_PATH>;Extended Properties="Excel 12.0;HDR=YES";

You can try replacing the highlighted text with the actual file path consisting of the file name and extension along with the full file path. For example: "C:\Test\Test.xlsx"

NOTE: Many times the connection string may not work depending on the excel version and Extended Properties. In case it does not work you can refer to the following website where you can find all the alternatives to your connection string to try upon: Connection Strings

- After this action you can use the "Open" action of the "Data - OLEDB" VBO to open the connection to the excel file and then use "Get Collection" of the "Data - OLEDB" VBO action to execute the query which you want to send in order to fetch the data which in your case would be the count for a specific column. The query format is more or less like your SQL queries which you can use like SELECT COUNT(COLUMN_NAME) FROM SHEET_NAME$COLUMN_LETTER:COLUMNLETTER


Substitute the 'COLUMN_NAME' value with the actual header name that you have and the 'SHEET_NAME' with the actual sheet name you have. Also you can substitute the 'COLUMN_LETTER' with the that specific column heading if you want to limit the range,


This action will provide you the count of entire result set of this query into a collection. You can use this value going ahead in your automation

- Post this you can now close the connection by using "Close" action of the "Data - OLEDB" VBO.


Also, if you get some error while installing the MS Access Database Engine, I have a exe setup file for it, since I don't remember the exact source URL from where I downloaded it but I am sharing the drive link where I have that exe file saved: Access Database Engine Installation

DISCLAIMER : Please download at your own risk as it is not being provided or promoted by me.

------------------------------
----------------------------------
Hope it helps you and if it resolves you query please mark it as the best answer so that others having the same problem can track the answer easily

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
Wonderbotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.