export to excel with a blank row shown top--how to get rid of it?

G

Guest

I have the following routine to export gridview data to excel. The excel file
has an extra line added on the top. Is there anyway to get rid of it? The
environment of dev box is WindowsXP, Msft windows frmwk 2, VS2005, Office
2003. Any help would be very much appreciated.

===============================================
Protected Sub ibtnExcel_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ibtnExcel.Click

'Dim streamwriter As HTMLS
Dim defaultFileName As String = "MyTestExcelFile"

Response.Clear()
Response.Buffer = False
Response.BufferOutput = False

Response.ContentType = "application/ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=" +
defaultFileName + ".xls;")

Response.Charset = ""
Me.EnableViewState = False

Dim sw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(sw)

Dim frm As HtmlForm = New HtmlForm()
Me.Controls.Add(frm)
grdQueryResult.AllowSorting = False
grdQueryResult.AllowPaging = False
grdQueryResult.DataSource = Session("Sql_select")
grdQueryResult.DataBind()
frm.Controls.Add(grdQueryResult)
frm.RenderControl(hw)

Response.Write(sw.ToString())
Response.End()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top