The first version of Magento 2 was released 2 years ago! Many modules were made in this period, but there could have been more if everybody was using Mage2Gen. If you are not using Mage2Gen you now should take this change to save time and create more modules!
Magento 2 Creating a csv file
This post shows you how to create an csv file in a Magento 2 controller and return a download response.