I require to export list items from a SharePoint list to Excel. The order of items in the Excel sheet should be the same as in the list. Can somebody suggest console application code for this?
Here there's one way to do it.
The only thing missing is the OrderBy clause, as you stated you want to keep the same order (I guess you set a sort criterion on your AllItems view).
So you need to add this code snippet:
// Build a query with an orderby clause
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='YOUR_SORT_COLUMN' /></OrderBy>";
SPListItemCollection items = list.GetItems(query);
foreach (SPListItem item in items)
//use the code showed in the linked page
check out my solution, its pritty much the same using the for loop... the view would be default as is... when it loops throught it would get all list items within a list as its shown on sharepoint.
as for excel witin the app you need to import the interop reference!
full detail here:
with those two you should get your result!