Extract content from the Excel Using LINQ

How to extract data from excel using LINQ,

here’s the spreadsheet,
challenge(3).xls (29 KB)

Expected Output :-
1 : a, b
2 : c, e
3 : d, g
4 : f

@samir Can you provide the condition to extract those values.

Thank you for the reply, @ranjith
there’s no any condition, it should extract all the data but,

here’s my Excel Data

  1. it should get Distinct Id’s
  2. should display data releted to that id by seperating “,”

and then it should display the expected output in Output Pane. (as i mentioned in my topic)


I am not sure how to achieve your problem using LINQ. Hope @arivu96 will help you on this.

(from x in DT_Input Group By Distinct = New With {Key .ID = CStr(x(“ID”))} Into Group From g In Group Select g ).copytodatatable

Using the above query you can group the rows with ID values. If you need i can help you to solve this without using LINQ.

Hi @samir
(From p In dt.DefaultView.ToTable(False,"ID","Role").Select Group p By ID=Convert.ToString(p("ID")) Into GroupA=Group Let x=GroupA(0)("ID").ToString+"|"+String.Join("-",(From p In GroupA Select Convert.ToString(p("Role"))).ToArray) Select dt.DefaultView.ToTable(False,"ID","Role").Clone().Rows.Add(x.ToString.split("|"c))).ToArray.CopyToDataTable()

Arivu :slight_smile:


hey thanks @ranjith,
yeah i got it, and @arivu96 solved my problem. :slightly_smiling_face:

hey thanks for the reply and you solved my problem.
i got the output like this…

could you please tell me… from where i can learn LINQ and practice queries,
I want to learn this because when i see these linq queries i get idea of how it works and for my learning I only make changes in that query so, is there any material or a link where i can learn this ?

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