Excel -Data table to dictionary


Workflow_1 → Data Source will be from excel (stored in a Data table)
Workflow_2 → Input the data source in the form of Dictionary<String, object>

Excel data format


Is there is way to iterate this data table and feed the dictionary assuming the key as 1 and values as A,B,C,D,E

Dictionaries are key/value pairs. You can’t have a key of 1 with values A, B, C, D, E. Each key has one corresponding value.

What you could do is a key of 1 with a value of {“FGH1”,“SWE1”,“DFR1”,“TYU1”,“OPI1”} which is a list.

We assume that the values given within the table are samples and real data will be different
Otherwise we would handle an access by
dtData.Rows(number - 1)(ColNameOrIndex)

Following the question:

we could model it like (one of many options):

New Dictionary(Of String, Object) From {
{"1", new object(){"SWE","DFR1","TYU1","OPI1"}}

The Dictionary as an illustration, how the result would look like

But each access of the A,B,C,D,E values would require a casting like:
DirectCast(myDict("1"), Object())(2) → getting the C Value

So we would recommend to elaborate more at the motivation, why convert it into a dictionary and how the usage / access is needed. Maybe we can suggest a more fitting alternate, when we do know more about the use case and what is aimed.

dictvar=New Dictionary(Of String, String())()

dictvar=Dt.AsEnumerable().ToDictionary(Function(row) row(0).ToString(), Function(row) row.ItemArray.Skip(1).Select(Function(x) x.ToString).ToArray())

Hope It Helps!!