Using Workflow,How to save the result of a script in Excel file and download the file using workflow

I have to create a script/query in a workflow which can return all the roles associated with a user.

And i need this result to be saved in an Excel File and need to download this Excel file using the same workflow.

Any idea how to implement this?