How to export report data from SQL / ASP.NET to .XLS using color and formatting?
This solution is pretty clever. It uses StringWriter to export datagrid to excel file using mime type:
http://blog.aasheim.org/2008/03/export-data-from-web-page-to-excel.html
a source to share
I got lucky with these guys: http://officewriter.softartisans.com/OfficeWriter-257.aspx
Not cheap, but the object model is very elegant and you have a lot of control over the look. (I was using a previous version of COM and I assume newer versions are good as well.)
a source to share
- Magic
If you want to rely on the magic of MS Excel, you can install
Response.ContentType = "application/vnd.ms-excel";
create a table inside the HTML output and let Excel interpret it as if it were an XLS file.
If you are using custom colors, you probably need to add them to the <HEAD> section, as I just found in one of my past projects:
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:Colors>
<o:Color>
<o:Index>16</o:Index>
<o:RGB>#E10056</o:RGB>
</o:Color>
<o:Color>
<o:Index>17</o:Index>
<o:RGB>#d4d1b8</o:RGB>
</o:Color>
</o:Colors>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
- Office automation
Use Excel COM Automation to create a real XLS backend and submit it via Response.WriteBinary
- Third party tool
as Matt answered
a source to share