How to properly read dates from a csv / excel file
I have a CSV file that needs to be opened in excel. I want to read an entire row at a time into my program and store it in some kind of list or array. In past projects I have used:
DateTime[] dates = xlworksheet.get_Range("B7", "B"+xlWorksheet.Rows.Count);
This is giving me the error: "Cannot convert type 'object[,]' to 'System.DateTime[]'". This makes sense but I don't know how to store the entire开发者_JS百科 column other wise. How do I read an entire column from an excel worksheet into a list/array in my program?
I am assuming you are using .NET 3.5 or higher. Add a using System.Linq;
DateTime[] dates = xlworksheet.get_Range("B7", "B"+xlWorksheet.Rows.Count).Cast<DateTime>().ToArray();
精彩评论