You may want to generate an Excel spreadsheet on your Web site using data in your database. This is the easiest and most reliable way to do it.
Put together a SQL query that gets the data from your Web site database and puts it into the query results. For example:
SELECT firstname, lastname, message FROM mytable
Using the programming language of your choice, build a CSV file (comma-separated values), putting the header row at the top. Output it to your Web browser's screen in the usual way, so you can verify the CSV. Unless you are absolutely sure that your field will be numeric you should enclose it with quotes. If you think that your field results might have quotes in it, change these to double quotes first. For example:
"First Name","Last Name","Message" "Bob","Smith","Hi there!" "Jane","Van Wild","You are ""so"" cool"
Run the Web page and verify that your content looks like a CSV file (you'll have to view the page source)
Above the output on your page and before any and all output, you'll need to tell the page that it needs to generate a CSV. It's also good practice to name the file that your user is downloading. This is done by sending header information. The exact function you use depends on the programming language you're using. Here is an example for PHP, with the month and year set earlier in the script: