How to Read Excel Data in Coded Workflow using UiPath In-built Excel Activities?

What is the procedure for integrating and utilizing the in-built Excel activities of UiPath within a coded workflow?

The question seeks detailed guidance on the step-by-step process of incorporating and utilizing the pre-existing Excel automation capabilities provided by UiPath within a programmatically defined workflow. It implies a desire to understand not only the mechanics of using these features but also their integration into a larger automation solution driven by code.

Hi, @urvesh.mistry - Your question not clearly understand about what exactly you wanted. What does that mean by coded workflow?

You can do this if you want to create a workflow and using it, you can add workflow and add Excel code, invoke into your code.

You can check the below activity for reading Excel.

Hi @ABHIMANYU_THITE1,

Kindly find the attached image below where we perform the automation by doing coding as shown in image.

Where as “coded workflow” is type of workflow in UiPath. You can see the same in the attached image.

image

Now, The answer I am seeking is how can we use UiPath In-Build Activities in this “coded workflow” in-order to perform excel automation.

I hope now my query is clear to you.

Thanks & Regards,
Urvesh Mistry

@urvesh.mistry

Give a try like below:

To integrate and utilize UiPath’s built-in Excel activities within a coded workflow, you’ll need to follow these steps:

  1. Set Up Your UiPath Project:
    Create a new UiPath project in UiPath Studio.
    Ensure that the required dependencies for Excel automation are installed.
  2. Add Required Namespaces:
    In your coded workflow (e.g., a sequence or flowchart in a .xaml file), import the necessary namespaces to access UiPath’s Excel activities. The main namespace for Excel activities is UiPath.Excel.Activities.
  3. Instantiate Excel Application Scope:
    Create an instance of the ExcelApplicationScope activity to open and manage Excel files. This activity provides a container to execute Excel-related activities within.
    Configure the properties of the ExcelApplicationScope activity, such as the file path of the Excel workbook.
  4. Add Excel Activities:
    Within the ExcelApplicationScope, add Excel activities such as Read Range, Write Range, Append Range, etc., to perform desired operations on the Excel workbook.
    Configure the properties of each activity as needed, such as specifying the range of cells to read or write.
  5. Run the Workflow:
    Execute your coded workflow, either directly from UiPath Studio or by triggering it through an automation trigger such as a scheduled task or a UiPath Robot execution.

Thanks.

@urvesh.mistry - try below - rather than sample give your excel workflow xaml file path, if it has argument the needs to pass as dictionary

image

Hi @naveen.s,

Thank you for your response but I am aware of working fundamentals of the excel activities. It would be helpful if you can help with the coding. So far there are no official written documents in the same regards.

Hi @ABHIMANYU_THITE1,

I am aware of the solution which you are suggesting but here, I am trying to explore the coded workflow to it’s full extent and really wanted to learn, how to perform excel automation using coded workflow.

@urvesh.mistry,

Can you try like this:

Imports UiPath.Excel.Activities
Imports System.Activities
Imports System.Activities.Statements

Public Class Main
Inherits CodeActivity

Protected Overrides Sub Execute(ByVal context As CodeActivityContext)
    ' Set up Excel Application Scope
    Dim excelScope As New ExcelApplicationScope()

    ' Configure properties of Excel Application Scope
    excelScope.WorkbookPath = "C:\path\to\your\excel\file.xlsx"

    ' Add Excel activities within Excel Application Scope
    Dim readRangeActivity As New ReadRange()
    readRangeActivity.Range = "A1:B5" ' Specify the range of cells to read
    readRangeActivity.SheetName = "Sheet1" ' Specify the name of the worksheet
    ' Add other properties and configurations as needed

    ' Run the workflow
    Dim workflow As New Sequence()
    workflow.Activities.Add(excelScope)
    workflow.Activities.Add(readRangeActivity)

    Dim workflowInvoker As New WorkflowInvoker(workflow)
    workflowInvoker.Invoke()
End Sub

End Class

Hi @naveen.s,

I have performed the similar code, but it is showing error like this.

image

As you can see in the image, “WorkbookPath” takes “InArgument” (InArgument of String).

@urvesh.mistry

Can you try like below:

Instead of setting the WorkbookPath property after creating the ExcelApplicationScope object, you can pass it directly to the constructor.
Here’s how you can simplify the initialization:

Dim excelScope As New ExcelApplicationScope(“C:\path\to\your\excel\file.xlsx”)
Add Reference to System.Activities:

In UiPath Studio, open your project.
In the Solution Explorer, right-click on the References node.
Select “Add Reference…”.
In the “Add Reference” window, search for “System.Activities” in the “.NET” tab.
Check the checkbox next to “System.Activities” and click “OK” to add the reference.
This will resolve the CS0012 error.