Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Export your <code>application/vnd.ms-excel</code> as an HTML table, it gives you access to a variety of worksheet formatting options:</p> <p>Use:</p> <pre><code>Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("content-disposition", "attachment; filename=" + fileName); </code></pre> <p>And send something like the following:</p> <pre><code>&lt;table border="1"&gt; &lt;caption&gt;This is a caption, it appears centered across all columns&lt;/caption&gt; &lt;colgroup&gt; &lt;col width="100"&gt; &lt;col width="200"&gt; &lt;/colgroup&gt; &lt;tr valign="bottom"&gt; &lt;td&gt;&lt;b&gt;Header 1&lt;/b&gt;&lt;/td&gt; &lt;td filter="all"&gt;&lt;b&gt;Header 2 (filterable)&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td style="vnd.ms-excel.numberformat:$#,##0.00_)[semicolon]($#,##0.00)"&gt;1&lt;/td&gt; &lt;td style="vnd.ms-excel.numberformat:00000000"&gt;2&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td style="vnd.ms-excel.numberformat:$#,##0_)[semicolon]($#,##0)"&gt;3&lt;/td&gt; &lt;td style="vnd.ms-excel.numberformat:00000000"&gt;4&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td style="vnd.ms-excel.numberformat:$#,##0.00_)[semicolon]($#,##0.00)"&gt;-5&lt;/td&gt; &lt;td style="vnd.ms-excel.numberformat:00000000"&gt;2&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td style="vnd.ms-excel.numberformat:$#,##0.00_)[semicolon][red]$#,##0.00"&gt;-7&lt;/td&gt; &lt;td style="vnd.ms-excel.numberformat:00000000"&gt;8&lt;/td&gt; &lt;/tr&gt; &lt;tr valign="bottom"&gt; &lt;td formula="=sum(a2:a5)" style="vnd.ms-excel.numberformat:$#,##0.00_)[semicolon][red]$#,##0.00"&gt;&lt;/td&gt; &lt;td formula="=average(b2:b5)" style="vnd.ms-excel.numberformat:00000000"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Note that by using the HTML table syntax you can add a <a href="http://archive.baarns.com/DevOnly/Notes/TechEd/Intr9713.asp" rel="nofollow noreferrer">column AutoFilter</a>, specify the vertical row alignment, control the width of columns, combine columns with <code>&lt;colspan&gt;</code> (not shown), add <a href="http://archive.baarns.com/DevOnly/Notes/TechEd/Intr9711.asp" rel="nofollow noreferrer">formulas</a> and specify the format of column data with <a href="http://archive.baarns.com/DevOnly/Notes/TechEd/Intr9712.asp" rel="nofollow noreferrer">vnd.ms-excel.numberformat</a>. You can even do <a href="http://archive.baarns.com/DevOnly/Notes/TechEd/Intr9714.asp" rel="nofollow noreferrer">Crosstab (PivotTables)</a> (not shown).</p> <p>I had a link to more comprehensive documentation about what HTML tags and attributes are supported, and what they do, but I seem to have misplaced it. If anyone else has a good link to Microsoft documentation about this, feel free to <a href="https://stackoverflow.com/posts/1209326/edit">edit my answer</a> or include a comment.</p> <p>EDIT: It seems that you can do <a href="http://www.c-sharpcorner.com/UploadFile/kaushikborah28/79Nick08302007171404PM/79Nick.aspx" rel="nofollow noreferrer">a lot more with HTML/XML</a> to build complicated Excel worksheets. I've never gone to these lengths, but it is interesting to know what is possible.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload