I've a list like this:
internal class Order
{
public Order()
{
}
public string ProductID { get; set; }
public int Amount { get; set; }
public string Date { get; set; }
}
List<Order> orderList = new List<Order>()
{
new Order(){ ProductID="12345", Amount=300, Date = "2018-12-19"},
new Order(){ ProductID="12345", Amount=0, Date = "2018-12-20"},
new Order(){ ProductID="12345", Amount=200, Date = "2018-12-21"},
new Order(){ ProductID="12345", Amount=250, Date = "2018-12-22"},
new Order(){ ProductID="12345", Amount=30, Date = "2018-12-23"},
new Order(){ ProductID="67898", Amount=20, Date = "2018-12-20"},
new Order(){ ProductID="67898", Amount=30, Date = "2018-12-21"},
new Order(){ ProductID="67898", Amount=40, Date = "2018-12-22"},
new Order(){ ProductID="67898", Amount=50, Date = "2018-12-23"},
new Order(){ ProductID="67898", Amount=130, Date = "2018-12-24"}
};
In this situation, when I convert the list to DataTable
and export it to excel, I get this:
I want to create new columns from Date values and list them by ProductID. How can I convert this List to DataTable
to see like this: