Linq query data extarction


I need to extract this data from excel using linq query

1 Like

Hi

You can simply read it with READ RANGE activity and get the output as a datatable

If u want to read the excel with linq query first I need to read the excel with a vb script

As you don’t know the specific range of the Excel table, you can use the following VB.NET expression in an Invoke VBA activity to load the entire Excel sheet into a DataTable in UiPath:

Sub LoadDataIntoDataTable()
    Dim excelApp As Object
    Dim excelWorkbook As Object
    Dim excelWorksheet As Object
    Dim dt As Object

    ' Open Excel and the workbook
    Set excelApp = CreateObject("Excel.Application")
    Set excelWorkbook = excelApp.Workbooks.Open("C:\Path\To\Your\Excel\File.xlsx") ' Replace with your file path

    ' Set the worksheet you want to read data from
    Set excelWorksheet = excelWorkbook.Sheets("Sheet1") ' Replace with your sheet name

    ' Load data into a DataTable
    Set dt = CreateObject("System.Data.DataTable")

    ' Copy the data from the Excel worksheet to the DataTable
    dt = excelWorksheet.UsedRange.Value

    ' Close Excel without saving changes
    excelWorkbook.Close False
    excelApp.Quit

    ' Return the DataTable
    Set ExtractDataIntoDataTable = dt
End Sub

Then try with this linq query in a assign activity

dt = dt.AsEnumerable().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or (field IsNot Nothing AndAlso String.IsNullOrWhiteSpace(field.ToString)))).CopyToDataTable()

Cheers @ajnaraya