Depending on your data, you don’t actually need to build additional logic to export a template grid’s entries to Excel (assuming you wish to get users to download the data rather than keep it in your app as a file).
The one thing you need to make sure is that the template grid’s source is set to Xpath. With this you can then add an ‘Export to Excel’ button right within the template grid’s control bar.
This is of course for exporting. For downloading properly (and use it within the app proper rather than something a user does manually) I think you will need to build a microflow (or java action) for downloading. My advice for that is to then use the same retrieve as you use for the template grid, and replicate it to said microflow and add it as a button next to or within the template grid for UX purposes.
DataGrid, supports default Export to Excel option which only exports the columns shown in the data grid.
TemplateGrid does not support the default Export to excel option.
If you really need to use TemplateGrid then look for ExcelExporter Appstore module, with which you can configure the excel templates and export the data.