Generate csv from backend data

Is there a way to generate CSV from backend data and let the user download it by button click