I've always outputed it as an HTML table with an XLS file extension. Excel
is able to interpret it as a regular worksheet. However, if you want to
output a workbook (multiple tables across multiple sheets), you will need to
output to the Excel XML-based format and Strong.Format in the user ID,
company name, and workbook XML based on this template (it's escaped for
appearing in an XML-based .resx file) (and subsequently do a Response.Write
of the resulting string):
The response content header:
HttpResponse response = HttpContext.Current.Response;
response.ContentType = "application/vnd.ms-excel";
response.Charset = String.Empty;
response.AddHeader("Content-Disposition",
"attachment;filename=report.xlw");
The template:
<data name="ExcelWorkbook">
<value><?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns:ss="urn:schemas-microsoft-com
ffice:spreadsheet"
xmlns:html="
http://www.w3.org/TR/REC-html40">
<DocumentProperties
xmlns="urn:schemas-microsoft-com
ffice
ffice">
<Author>{0}</Author>
<LastAuthor>{1}</LastAuthor>
<Created>{2}</Created>
<Company>{3}</Company>
<Version>10.3501</Version>
</DocumentProperties>
<OfficeDocumentSettings
xmlns="urn:schemas-microsoft-com
ffice
ffice">
<RelyOnVML/>
<AllowPNG/>
<DownloadComponents/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com
ffice:excel">
<WindowHeight>9720</WindowHeight>
<WindowWidth>14235</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>135</WindowTopY>
<ActiveSheet>0</ActiveSheet>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="Header">
<Font ss:Bold="1"/>
</Style>
<Style ss:ID="ShortDateCell">
<NumberFormat ss:Format="m/d/yyyy;@" />
</Style>
</Styles>
{4}
</Workbook>
</value>
</data>