If I don't understand wrong, you can do it as I explained. For example; Let me say I have a link says "Download all data as an Excel file" in my web site. It should go to an asp page when it is clicked, for example ; datatoexcel.asp.
You can create datatoexcel.asp such that at the top of the page "Response.ContentType = "application/vnd.ms-excel" is placed. Then you can dynamically get your data from your database as dynamically created tables into your asp file. So when "Download all data as an Excel file" link is clicked, your datatoexcel.asp file tell client's browser that an excel file is coming. So browser want to download file and let user to save file.
You can take look at this link :
http://www.codetoad.com/asp_excel.asp
There is another way to create an excel file. In this method you create an office document object on the server side. But this requires that necessary component must be installed on the web server.
You can read this article about this method :
http://www.4guysfromrolla.com/webtech/022801-1.shtml