Bartosz Bartosz - 9 months ago 63
ASP.NET (C#) Question - exporting table

I have a big problem with exporting my table to Excel file format.

Firstly I created code which runs on server and allows me to export data to Excel. Due to the fact that my table is created dynamically from the database there is nothing WITHIN the table at that stage, so no data were exported.

My second approach was targeting the final compiled table on the client side using either javascript or a very nice jQuery plugin called "DataTables" ( Both of the attempts failed. Javascript seems to be to complex for me, plus it has difficulties running in Firefox, plugin on the other hand requires a very specific table structure which I am afraid I cannot provide.

So, a new idea of mine is: grab the page just after compiling and building it on the server, but before sending it to the browser. Target THE table and source its data using function on server. Finally export data to Excel, and send the page to the browser. Now. Is it possible? And if yes, then how?

I am beginner in programming world so any constructive suggestions and criticism would be highly appreciated. I would not mind any hard code examples ;)

Answer Source

What you need to do is export your query results in a .CSV file. CSV files can be opened in Excel no problem at all. This shows you how to export into a .CSV format.