Try something like this:
var customer1 = from c in excel.Worksheet() select new { Product = c["Product"], Location = c["Location"], Customer = "Customer1", Demand = c["Customer1"], }; var customer2 = from c in excel.Worksheet() select new { Product = c["Product"], Location = c["Location"], Customer = "Customer2", Demand = c["Customer2"], }; var customer3 = from c in excel.Worksheet() select new { Product = c["Product"], Location = c["Location"], Customer = "Customer3", Demand = c["Customer3"], }; var customers = customer1.Union(customer2).Union(customer3);
Based on your comment, try the following:
var columns = 4; var customers = from n in Enumerable.Range(2, columns) from c in excel.Worksheet() select new { Product = c["Product"].Value, Location = c["Location"].Value, Column = n.ToString(), Demand = c[n].Value, };
source share