I am exporting a HTML table to excel by sending the data as a HTML Table string and setting the content headers:
Dim html as String = "<table><tr><td>example<td></tr></table>"
context.Response.Clear()
context.Response.AddHeader("Content-Disposition", "attachment; filename=" & "exceldata-" & Now.ToString("yyyyMMddHHmmss") & ".xls")
'context.Response.AddHeader("Content-Length", ????)
context.Response.ContentType = "application/octet-stream"
context.Response.Write(response)
context.Response.End()
Is there a simple way of setting the content-length based on the size of the html string? Or should I just leave it blank anyway…would be nice to have the content-length ideally…
I am returning this using a GenericHandler in asp.net
Replace with the encoding of your choice, probably UTF8. Sorry for the C#:
Source: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.contentlength.aspx