Hi all,
Hoping someone can shed some light on this one...
We have a web page that exports the contents of a datareader to Excel, using the attached code. All works well most of the time, except for larger extracts. For some reason, the resulting spreadsheet is quite large (ie 11.5mb). When we go to save it in Excel, the default type is set to WEB PAGE (*.htm,*.html). When we change this to Excel, and save, the resulting file is now 5mb.
Is there any reason why the produced file from the web page would be so much larger, and not defaulting to type .XLS?
Any help would be greatly appreciated.
Thanks in advance,
Yazster
Hoping someone can shed some light on this one...
We have a web page that exports the contents of a datareader to Excel, using the attached code. All works well most of the time, except for larger extracts. For some reason, the resulting spreadsheet is quite large (ie 11.5mb). When we go to save it in Excel, the default type is set to WEB PAGE (*.htm,*.html). When we change this to Excel, and save, the resulting file is now 5mb.
Is there any reason why the produced file from the web page would be so much larger, and not defaulting to type .XLS?
Any help would be greatly appreciated.
Thanks in advance,
Yazster
Code:
Public Shared Sub ConvertToExcel(ByVal dr As SqlDataReader, ByVal response As HttpResponse)
response.Clear()
response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
response.AddHeader("Content-Disposition", "attachment;filename=MyExport.xls")
Dim objSB As StringBuilder = New StringBuilder("")
Dim intFieldCnt As Integer
objSB.Append("<style>")
objSB.Append(".text {mso-number-format:\@;}")
objSB.Append("</style>")
objSB.Append("<Table cellspacing=""0"" cellpadding=""0"" border=""1"" bordercolor=""#000000"" width=""100%"" style=""font-size:8pt;"">")
'Header captions
objSB.Append("<TR bgcolor=""#D0D0D0"">")
For intFieldCnt = 0 To dr.FieldCount - 1
objSB.Append("<TH>" & dr.GetName(intFieldCnt) & "</TH>")
Next
objSB.Append("</TR>")
'Data fields
Dim strTextFields As String = AvalancheFunctions.GetExcelFormatFields("TEXT")
While dr.Read()
objSB.Append("<TR>")
...
objSB.Append("</TR>")
End While
objSB.Append("</Table>")
response.Write(objSB.ToString())
response.End()
End Sub