Generate CSV/Excel sheet from database

Hi again folks,
I have a page only accessible for loged users that shows content from a database.
On this page I have put a button “Export/Save list as CSV”.
How can I generate CSV/Excel sheet by clicking this button ?
My programmation skills are not so great as I want…

You could use a library
like Papa Parse, which works well for CSV,
and sheetjs if You really need an Excel Sheet (which requires a little more effort in scripting, in my opinion.) They have also setup a few demos.

This is, of course for the frontend, so You would need to parse the generated html-table.
There’s also a php library, but I have never used it before…