views:

362

answers:

2

How to export MVC detail view data to excel file? What's the simplest solution?

+2  A: 

I think this is a great post that can help: Creating Excel spreadsheets .XLS and .XLSX in C#

CD
A: 

If you will not be storing equations, functions, charts, or any other of the Excel goodies and you will only want to export data that can be opened in Excel, there is the option of creating Comman Separated Files (CSV). This is a format recognized by Excel and will let you arrange your data in a easy way.

Just write a simple text file qith the following format:


header1,header2,header3,......,headerM
row1col1,row1col2,row1col3,......,row1colM
row2col1,row2col2,row2col3,......,row2colM
....
....
....
rowNcol1,rowNcol2,rowNcol3,.....,rowNcolM

In my opinion is the fastest and easier way to export data into Excel, the constraint is that you could not have multiple sheets nor any of the excel objects.

Freddy