On a site we are building, users have the ability to sort and page data. There is also an export function which returns data from all pages.
Should the data be sorted in the same way that it is on screen or in its original, unsorted order? Why?
I'd say it depends on the destination of the export.
If it can do sorting (or indeed any form of processing) then it probably doesn't matter whether the data is exported in it's sorted form or not. In this case the data is likely to be sorted (processed) in the target application so exporting the data sorted might be counter-productive. As this is the usual case then don't export the sorted data.
If the destination can't do sorting then I'd recommend keeping the sort order specified by the user.
The only thing I would add is that if the data is filtered (i.e. the user has selected a subset of the data) then only the selected data should be exported.
The most common way to export tabular data is in CSV, if that is the case then no need to add sorting as Excel and other programs will handle that just fine for the user.
Absolutely.
You need to maintain consistency between what a user sees on the screen and what they get within the exported CSV/Excel file. You shouldn't force the user to re-preform the actions that they took on screen when filtering, sorting, showing/hiding columns, reordering columns, etc.
The user should be driving the action and telling the UI and its export what to do.
Maintain expectation.