views:

449

answers:

3

Would like to be able to set colors of headings and such, different font sizes and background colors for cells.

C# please.

A: 

This solution is quite clever. It uses a StringWriter to export a datagrid to an excel file using a mime type:

http://blog.aasheim.org/2008/03/export-data-from-web-page-to-excel.html

Robert Harvey
A: 

I've had good luck with these guys: http://officewriter.softartisans.com/OfficeWriter-257.aspx

Not cheap, but the object model is very elegant and you have lots of control over appearance. (I used the previous COM version and am assuming the newer versions are as good.)

Matt Sherman
A: 
  • Magic

If you want to rely on MS Excel magic, you can set

Response.ContentType = "application/vnd.ms-excel";

create your table inside the HTML output, and let Excel interpret it as if it were an XLS file.

If you use non-standard colors, you probably need to add them inside 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 server-side, and send it via Response.WriteBinary

  • 3rd Party Tool

as answered by Matt

devio