Although not a complete step by step guide, I would advise you to look at the implementation of the Flat File Export module from the market place to get some idea on what it takes to provide this functionality.
The module uses a predefined configuration for the export and you would need to change this to a more dynamic solution.