int columnindex = 43; List<string> lst = new List<string>(); foreach (DataRow row in dtFarmerFarmReports.Rows) { var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString()); if (dict != null) { lst.AddRange(dict.Keys); } } var distinctList = lst.Distinct().ToList(); List<excelheader> excelheaderlist = new List<excelheader>(); foreach (var data in distinctList) { columnindex++; worksheet.Cells[2, columnindex].Value = data; ExcelHeader excelHeader = new ExcelHeader { colIndex = columnindex, colName = data }; excelheaderlist.Add(excelHeader); } foreach (var dicdata in dict) { int colval = excelheaderlist.Where(x => x.colName == dicdata.Key).Select(y => y.colIndex).FirstOrDefault(); if (colval > 0) { worksheet.Cells[(j1), colval].Value = dicdata.Value; } }
foreach (var dicdata in dict)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)