简体   繁体   中英

Select certain columns programmatically from Excel spreadsheet based on a common identifier

After importing an excel sheet over to a windows form via a data-grid view. I need to select various columns and send them to the database. How do you select various columns based on a common identifier?

Excel sheet

图片

As you can see in the image, I would like to select the names based on the identifier. Is there any way to approach this?

This will give list of names based on identifier

                var mainDict = new Dictionary<string, Dictionary<string, List<string>>>()
        {
            {"Group1", new Dictionary<string, List<string>>{{"A", new List<string> {"bob", "steve", "greg"}}}},
            {"Group2", new Dictionary<string, List<string>>{{"B", new List<string> {"tom", "thomas", "justin", "lee"}}}},
            {"Group3", new Dictionary<string, List<string>>{{"C", new List<string> { "dustin", "rick" }}}}
        };

        var namesA = from m in mainDict where m.Value.ContainsKey("A") select m.Value.Values.First();
        var namesB = from m in mainDict where m.Value.ContainsKey("B") select m.Value.Values.First();
        var namesC = from m in mainDict where m.Value.ContainsKey("C") select m.Value.Values.First();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM