I am having trouble converting these expressions into lambdas without error (Cannot convert type error):
var excel = new ExcelQueryFactory(@"E:\MAHipotCepaStationProgram.xlsx");
//get list of program names
List<string> testNames = new List<string>();
testNames.AddRange(excel.Worksheet().ToList()
.Where(s => s["Program #"].Value.ToString() == "Program Title")
.Select(s => s[1].Value.ToString()));
//get list of program numbers
List<int> testNumbers = new List<int>();
testNumbers.AddRange(excel.Worksheet().ToList()
.Where(s => s["Program #"].Value.ToString() == "Program #")
.Select(s => Convert.ToInt32(s[1].Value)));
//combine them
Dictionary<int, string> programs = new Dictionary<int, string>();
for (int x = 0; x < testNames.Count-1; x++)
{
if (!programs.ContainsKey(Convert.ToInt32(testNumbers[x])))
{
programs.Add(Convert.ToInt32(testNumbers[x]), testNames[x]);
}
else
{
testNumbers[x].Dump("Duplicate Found");
}
}
We should be looking at something like the following but no matter what I try it won't compile:
Dictionary<string, string> programsDict = excel.Worksheet().ToDictionary(
e => e["Program #"].Value.ToString() == "Program Title")
.Select(s => s[1].Value.ToString()),
f => f.Where(d => d.Value.ToString() == "Program #").ToString());
Any help is much appreciated. Also, here is pic of the excel sheet we're trying to extract the data from, Program Titles and Program Numbers.