Hello,
our goal is to convert an excel file to a dictionary (of String, String).
The Excel file has 100+ columns so we don´t want the manual effort of typing in every value and key of the dictionary.
Is there any possibility to convert all data (Column Name = Tkey; Row Value = TValue) automatically to the dicitionary.
Assign Activity:
dictionaryData = New Dictionary(Of String, String)()
For Each Activity (For Each row In excelData.Rows):
For Each Activity (For Each column In excelData.Columns):
Assign Activity:
columnName = column.ColumnName
cellValue = row(columnName).ToString()
to interpret it within the direction that 100+Columns are to bring within the Dictionary where Columnname is the key we can do it for 1 row (using the second row would result to duplicated keys)
(From i in Enumerable.Range(0,YourDataTableVar.Columns.Count)
Let k = YourDataTableVar.Columns(i).ColumnName
Let v = YourDataTableVar.Rows(0)(i).toString.Trim
Select t = Tuple.Create(k,v)).ToDictionary(Function (t) t.Item1, Function (t) t.Item2)
My first question is why. Why are you trying to convert a datatable to dictionary, when you can just reference the values from the datatable directly?
Anyway, you can’t convert an entire datatable to dictionary. Dictionaries only store one value per key. You could convert a datatable row to a dictionary, but again there isn’t any point to this. What are you trying to accomplish?